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 I ++ in c programming?

886


What is pointer and structure in c?

801


why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above

921


What is meant by operator precedence?

896


Why n++ execute faster than n+1 ?

2375


What are near, far and huge pointers?

856


What is the use of volatile?

862


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

3758


Hi can anyone tell what is a start up code?

1859


How can you increase the size of a statically allocated array?

873


Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?

827


what are non standard function in c

1676


Write a C program to count the number of email on text

1696


what is the format specifier for printing a pointer value?

817


List the difference between a 'copy constructor' and a 'assignment operator' in C?

869