Write a program in C to demonstrate substring replacement
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[50],str1[15],str2[15],temp[50];
char *ptr;
int cnt;
clrscr();
printf(“enter a line of text..... \n”);
gets(str);
printf(“enter the string to be replaced... \n”);
gets(str1);
printf(“enter the replacing string...”);
gets(str2);
printf(“\n the replaced line of the text....”);
while(1)
{
ptr=strstr(str,str1);
if(ptr==?\o?)
break;
cnt=ptr-str;
strncpy(temp,str,cnt);
temp[cnt]=?10?;
strcat(temp,str+cnt+strlen(srt1));
strcpy(str1,temp);
puts(str);
}
getch();
}
Post a Comment