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
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
What is wild pointer in c with example?
What does the file stdio.h contain?
Explain logical errors? Compare with syntax errors.
What are qualifiers in c?
Why is c called a mid-level programming language?
What is logical error?
Explain argument and its types.
What is an arrays?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
number of times a digit is present in a number
What are the benefits of organizational structure?
Is main a keyword in c?
What are pointers really good for, anyway?
Is fortran faster than c?