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

What is the right way to use errno?

1009


What is pivot in c?

987


What is variables in c?

993


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.

2110


How can I change the size of the dynamically allocated array?

1108


There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?

1251


What is the difference between memcpy and memmove?

981


any "C" function by default returns an a) int value b) float value c) char value d) a & b

1050


What are preprocessor directives in c?

1049


Why is sprintf unsafe?

1005


What is malloc and calloc?

1016


#include #include struct stu { int i; char j; }; union uni { int i; char j; }; void main() { int j,k; clrscr(); struct stu s; j=sizeof(s); printf("%d",j); union uni u; k=sizeof(u); printf("%d",k); getch(); } what is value of j and k.

6216


What is the code for 3 questions and answer check in VisualBasic.Net?

2113


Should I learn data structures in c or python?

985


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

1215