Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

1133


What is wild pointer in c with example?

1108


What does the file stdio.h contain?

1117


Explain logical errors? Compare with syntax errors.

1124


What are qualifiers in c?

1086


Why is c called a mid-level programming language?

1241


What is logical error?

1181


Explain argument and its types.

1111


What is an arrays?

1135


Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

1142


number of times a digit is present in a number

2077


What are the benefits of organizational structure?

1060


Is main a keyword in c?

1178


What are pointers really good for, anyway?

1115


Is fortran faster than c?

1082