Tuesday 24 July 2012

frequency of a given string within the string

/*How To find the frequency of a given string within the string*/

#define MAXS 256

void main()

{

char s[MAXS],t[MAXS];

char *p;

int count=0;


// Accept string

printf("Enter some string:\n");

gets(s);


//Accept substring

printf("Enter search pattern:\n");

gets(t);


//Move pointer to the begining of string

p=s-1;


// Check for the substring and increment its occurence

while((p=strstr(p+1,t))!=NULL)

{

count++;

}

printf("Number of occurences=%d",count);

}
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: