/* SUBSTRING DETECTION, COUNT AND REMOVAL */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[50],s2[50],a[50],s3[50],r[10];
int i,j,k,c,l1,l2,s=0,p1[10],p=0;
clrscr();
printf("\n\t\tINPUT:");
printf("\n\t\t------");
printf("\n\t\tEnter the string: ");
gets(s1);
printf("\n\t\tEnter the substring: ");
gets(s2);
l1=strlen(s1);
l2=strlen(s2);
c=0;
for(i=0;i<l1;i++)
{
k=0;
if(s1[i]==s2[0])
{
for(j=i;j<i+l2;j++)
{
a[k]=s1[j];
k++;
}
a[k]='\0';
if(strcmp(a,s2)==0)
{
p1[p]=i+1;
p++;
c++;
i=i+l2-1;
}
}
else
r[s++]=s1[i];
}
r[s++]='\0';
printf("\n\t\tOUTPUT:");
printf("\n\t\t-------");
for(p=0;p<c;p++)
printf("\n\t\t'%s' occurs at position %d in
'%s'",s2,p1[p],s1);
if(c==0)
{
printf("\n\t\tSubstring '%s' is not found",s2);
}
else
{
printf("\n\t\tSubstring '%s' is found at %d times in
'%s'",s2,c,s1);
printf("\n\t\tAfter detection of substring: %s",r);
}
getch();
}
INPUT:
------
Enter the string: programming
Enter the substring: m
OUTPUT:
-------
'm' occurs at position 7 in 'programming'
'm' occurs at position 8 in 'programming'
Substring 'm' is found at 2 times in 'programming'
After detection of substring: prograing
INPUT:
------
Enter the string: programming
Enter the substring: ds
OUTPUT:
-------
Substring 'ds' is not found
2 comments:
give flow chart for all programs
Frwd the algorithm for these program and flow chat
Post a Comment