C program that uses functions to perform the following operations: To insert a sub-string in to given main string from a given position.
#include
<stdio.h>
#include
<conio.h>
#include <string.h>
void main()
{
char a[10];
char b[10];
char c[10];
int p=0,r=0,i=0;
int t=0;
int x,g,s,n,o;
clrscr();
puts("\nEnter
First String:");
//puts is an unformatted output function
//puts is an unformatted output function
gets(a);
//gets is an
unformatted input function
puts("\nEnter Second String:");
gets(b);
printf("\nEnter
the position where the item has to be inserted:");
scanf("%d",&p);
r = strlen(a);
//strlen(string
) is a string function returns size of string entered
n = strlen(b);
i=0;
while(i <= r)
{
c[i]=a[i];
i++;
}
s = n+r;
o = p+n;
for(i=p;i<s;i++)
{
x = c[i];
if(t<n)
{
a[i] = b[t];
t=t+1;
}
a[o]=x;
o=o+1;
}
printf("%s",
a);
getch();
}
No comments:
Post a Comment