Write a c program to find, no of occurance of a given word
in a file. The word is case sensitive.

Answer Posted / ashutosh shashi

//function return occurance of word
int findoc(char* str,char* str1)
{
char* temp = str1;
int count =0;
while(*str != NULL)
{
while((*str == *temp)&&(*temp != NULL))
{
str++;
temp++;
if(*temp == NULL)
count++;
}
temp = str1;
if(*str != *temp)
str++;
}
return count;
}

///if function is called like

char* str = "ashashushuaashu";
char* str1 = "ashu";
int count = findoc(str,str1);
printf("%d",count);
///it prints 2, because str1 is appears 2 times in str

Is This Answer Correct ?    1 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the meaning of c in c language?

821


1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.

1914


What does int main () mean?

774


Can you write the function prototype, definition and mention the other requirements.

890


Is printf a keyword?

972


What is a pointer on a pointer in c programming language?

859


develop algorithms to add polynomials (i) in one variable

1945


How is a structure member accessed?

834


the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+....

23106


How many types of operators are there in c?

812


Is c is a middle level language?

811


Can a variable be both const and volatile?

890


What is a stream?

882


What is the code for 3 questions and answer check in VisualBasic.Net?

1921


What is the role of this pointer?

766