Thursday, September 20, 2012

program to find the occurrence of a string

" program to find the occurrence of a string"
#include<conio.h>
#include<stdio.h>
void main()
{
char st[20],t[10],a[20];
int i,j,c=0,r=0,l;
clrscr();
printf("Enter the string\n");
gets(st);   //reads the string
printf("Enter the search string\n");
gets(t);  reads the string
l=strlen(st);    //reads the length of the string
st[l]=' ';
for(i=0;i<=l;i++)
{
 if(st[i]!=' ')
 {
 a[r]=st[i];
 r++;
 }
  else
  {
  a[r]='\0';
  if(strcmp(t,a)==0) // compares the string
  {
  c++;
  }
  r=0;
  }

}
printf("\n%d",c);
getch();
}

No comments:

Post a Comment