Sunday 7 April 2013

Occurrences of character in string using c program

Occurrences of character in string using c program

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int j=0,i=0,count=0,p;
char name[100],text[100];
clrscr();
printf("enter the string\n");
gets(name);
printf("enter the word\n");
gets(text);
p=strlen(text);
while(name[i]!='\0'&&text[j]!='\0')
{
while(text[j]!='\0'&&name[i]!='\0')
{
if(name[i]==text[j])
{
j++;
}
else
{
j=0;
}
i++;
}
if(j==p)
{
count++;
}
j=0;
}
printf("count=%d",count);
getch();
}

No comments:

Post a Comment