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 meaning of c in c language?
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.
What does int main () mean?
Can you write the function prototype, definition and mention the other requirements.
Is printf a keyword?
What is a pointer on a pointer in c programming language?
develop algorithms to add polynomials (i) in one variable
How is a structure member accessed?
the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+....
How many types of operators are there in c?
Is c is a middle level language?
Can a variable be both const and volatile?
What is a stream?
What is the code for 3 questions and answer check in VisualBasic.Net?
What is the role of this pointer?