//Replace any word with a string;
#include
#include
#include
void main()
{
clrscr();
char str[50],word[10][15],rep_word[10],lrepw[20];
int i=0,l=0,len_word[10],k,j,o=0,p=0,a[10],lrep,check;
printf("Enter a string:");
gets(str);a[0]=-1;
printf("What word you want to replace:");
gets(rep_word);
printf("Enter the replaceing word:");
gets(lrepw);
lrep=strlen(lrepw);
while(str[i]!='\0')
{ k=0;
while(str[i]!=' ')
{ if(str[i]=='.')
{
a[o]=l;o++;break;
}
if(str[i]=='\0')
break;
word[l][k]=str[i];i++;k++;
}
i++;len_word[l]=k;l++;
}
for(i=0;i
{ for(j=0;j
{ if(word[i][j]!=rep_word[j])
{
check=0;break;
}
else
check=1;
}
if(check==1)
for(j=0;j
printf("%c",lrepw[j]);
else
for(j=0;j
printf("%c",word[i][j]);
if(i==a[p])
{
p++;printf(".");
}
else
printf(" ");
}
getch();
}
0 comments:
Post a Comment