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 are the 5 types of inheritance in c ++?
can any one provide me the notes of data structure for ignou cs-62 paper
Why is #define used?
What is the use of function in c?
What are the restrictions of a modulus operator?
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
What is derived datatype in c?
What is the difference between text files and binary files?
Does c have circular shift operators?
Write a program to reverse a given number in c language?
When can you use a pointer with a function?
What is data structure in c and its types?
Sir i need notes for structure,functions,pointers in c language can you help me please
What is the difference between a free-standing and a hosted environment?
How can I read in an object file and jump to locations in it?