/* PROGRAM TO INSERT A SUB STRING INTO MAIN STRING */
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char str[100],sub[50];
int len1,len2,i,j,pos;
clrscr();
printf("\nEnter Main String=");
gets(str);
printf("\nEnter Sub String=");
gets(sub);
printf("\nEnter Position For Insertion=");
scanf("%d",&pos);
len1=strlen(str);
len2=strlen(sub);
if(pos>len1)
printf("\nInsertion Operation Not Possible");
else
{
for(i=len1;i>=pos-1;i--)
str[i+len2]=str[i];
for(i=pos,j=0;j<len2;i++,j++)
str[i]=sub[j];
}
printf("\n After insertion the string is : ");
puts(str);
getch();
}
No comments:
Post a Comment