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 right way to use errno?
What is pivot in c?
What is variables in c?
1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.
How can I change the size of the dynamically allocated array?
There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?
What is the difference between memcpy and memmove?
any "C" function by default returns an a) int value b) float value c) char value d) a & b
What are preprocessor directives in c?
Why is sprintf unsafe?
What is malloc and calloc?
#include
What is the code for 3 questions and answer check in VisualBasic.Net?
Should I learn data structures in c or python?
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above