String replacing program using c
String replacing program
#include<stdio.h>#include<conio.h>
#include<string.h>
void main()
{
char mainstr[50],save[50],temp[50],save[50]repstr1[50];
int i,j,k,pos,count=0,len 1,l,n,m,frmlen,v,z,torep;
clrscr();
printf("Enter the main string:");
gets(mainstr);
printf("Replaced string:");
gets(repstr1);
printf("\n\n Postion where the string is to be replaced :\t");
scanf("%d",&count);
len1=strlen(repstr1);
j=0;
for(i=0;i<pos-1;i++)
{
save[j]=mainstr[i];
j++;
}
save[i]='\0';
frmlen=j;
torep=pos+count-1;
for(k=0;k<len;k++)
{
temp[k]=repstr1[k];
}
m=len1;
for(l=torep;mainstr[l]!='\0';l++)
{
temp[m]=mainstr[l];
m++:
}
temp[m]='\0';
frmlen=strlen(save);
v=strlen(temp);
for(n=0;n<frmlen;n++)
{
save2[n]=save]n];
}
z=n;
for(n=0;n<v;n++)
{
save2[z]=temp[n];
z++;
}
save2[z]='\0';
printf("\n String after replacement is :");
puts(save2);
getch();
}
Output
Enter the main string:Good morning missReplaced string:Night
Position where is to be replaced:6
Enter the number of character to be replaced :7
The string after replacement is :Good night miss
No comments: