|
Question
5
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[25],b[25],c[25],d[25];
int q,w,e,i,j,k;
clrscr();
printf("Enter the main string ");
fflush(stdin); /*flush the stdin in case of overflow*/
gets(a);
fflush(stdin); /*flush the stdin in case of overflow*/
printf("Enter the sub string ");
gets(b);
fflush(stdin); /*flush the stdin in case of overflow*/
printf("Enter the replacement string ");
gets(c);
fflush(stdin);
q=strlen(b); /*string length of b*/
w=strlen(c); /*string length of c*/
e=strlen(a); /*string length of a*/
strncpy(d,a,strlen(a));
if (q==w ) /*comparing two string before replacing*/
{ for(i=0;i<=q;i++)
{ fflush(stdin);
/*flush the stdin in case of overflow*/ for(j=0;j<=e;j++)
{
fflush(stdin);
/*flush the stdin in case of overflow*/ if(b[i]==a[j])
{
fflush(stdin);
/*flush the stdin in case of overflow*/ d[j]=c[i];
/*modifying main string according to the replacement string*/
fflush(stdin);
/*flush the stdin in case of overflow*/ }
}
}
printf("\Out put string=%s \n Substring= %s \n replace
%s",d,b,c);
}
else
printf("enter same length of strings retrun the program");
getch();
}
|