Write a function ustrcat(s1, s2, i) that concatenates contents of string s2 at the i position of string s1.

// Accept 2 string and insert 2nd string into first at given position

#include<stdio.h>
#include<conio.h>
#include<string.h>

void insert(char [],char [],int);
void main()
{
char a[80],b[80];
int i;
clrscr();
printf("Enter 1st string\n");
gets(a);
printf("Enter 2nd string\n");
fflush(stdin);
gets(b);
printf("Enter the position\n");
scanf("%d",&i);
insert(a,b,i);
getch();
}
void insert(char x[],char y[],int j)
{
int l1,l2,k;
l1=strlen(x);
l2=strlen(y);
 k=l1+l2;
for(;l1>=j;)
x[k--]=x[l1--];

for(k=0;y[k];)
x[j++]=y[k++];
printf("%s",x);
}





No comments:

Post a Comment

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number