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
I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
Explain how do you use a pointer to a function?
Which is better malloc or calloc?
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.
List the difference between a 'copy constructor' and a 'assignment operator' in C?
Write a program to swap two numbers without using third variable in c?
Explain what are the different data types in c?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
Explain what is a program flowchart and explain how does it help in writing a program?
How can I find the modification date of a file?
How can you restore a redirected standard stream?
Explain can you assign a different address to an array tag?
Explain logical errors? Compare with syntax errors.
Why pointers are used?
What is use of integral promotions in c?