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

I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

563


Explain how do you use a pointer to a function?

641


Which is better malloc or calloc?

654


a number whose only prime factors are 2,3,5, and 7 is call humble number,,write a program to find and display the nth element in this sequence.. sample input : 2,3,4,11,12,13, and 100.. sample output : the 2nd humble number is 2,the 3rd humble number is 3,the 4th humble number is ,the 11th humble number is 12, the 12th humble number is 14, the 13th humble number is 15, the 100th humble number is 450.

4545


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

639






Write a program to swap two numbers without using third variable in c?

619


Explain what are the different data types in c?

761


void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }

1262


Explain what is a program flowchart and explain how does it help in writing a program?

650


How can I find the modification date of a file?

706


How can you restore a redirected standard stream?

610


Explain can you assign a different address to an array tag?

648


Explain logical errors? Compare with syntax errors.

631


Why pointers are used?

633


What is use of integral promotions in c?

666