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
What is the difference between array and structure in c?
Explain the array representation of a binary tree in C.
When we use void main and int main?
Is that possible to store 32768 in an int data type variable?
How can a string be converted to a number?
What are pointers? What are different types of pointers?
write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?
What is the use of getch ()?
what will be the output for the following main() { printf("hi" "hello"); }
Can variables be declared anywhere in c?
Explain how are 16- and 32-bit numbers stored?
What will the code below print when it is executed? int x = 3, y = 4; if (x = 4) y = 5; else y = 2; printf ("x=%d, y=%d ",x,y);
What is variable in c example?
Why doesnt the call scanf work?
why wipro wase