C Source Codes List | Source Code Home
Program : Program to find the existence and frequency of an i/p sub-string in an i/p main string.
/* Prg. to find the existence & frequency of an i/p sub-string in an i/p
main string */
#include
#include
void insert(char str1[],char str2[]);
void main()
{
char a[80],b[80];
clrscr();
printf("\nEnter main string(i.e. str1):-\n");
gets(a);
printf("\nEnter sub-string(i.e. str2):-\n");
gets(b);
insert(a,b);
printf("\n\n\n\n\n\t\t\tHAVE A NICE DAY! BYE.");
getch();
}
void insert(char str1[],char str2[])
{
char c[80],d[80];
int i=0,j=0,k=0,count=0,l=0,k1=0;
for (i=0;(i<80 && str1[i]!='\0');i++)
{
c[i]=str1[i];
d[i]=str2[i];
}
l=strlen(d);
i=0;
while (c[i]!=EOF)
{
if (c[i]==d[j])
{
i++;
j++;
k1=1;
if (j==l)
{
j=0;
k=1;
count=count+1;
}
}
else
{
if (k1==1)
{
j=0;
k1=0;
}
else
i++;
}
}
if (k==1)
{
printf("\n\nThe given sub-string is present in the main string.");
printf("\nIt is present %d times.",count);
}
else
{
if (k==0)
printf("\n\nThe given sub-string is not present in the main string.");
}
return;
}
C Source Codes List | Source Code Home
|
|