-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrinsert.c
More file actions
55 lines (54 loc) · 1.05 KB
/
Copy pathstrinsert.c
File metadata and controls
55 lines (54 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*-------------------------------------------------------------------------------------------------------------------------------
strinsert.c
Program to insert a string into another
DIVYA RAJ K
11-11-2018
---------------------------------------------------------------------------------------------------------------------------------*/
#include<stdio.h>
#include<stdlib.h>
void strinsert(int N,char S[20],char T[20],char U[20]);
main()
{
char S[20],T[20],U[20];
int N;
system("clear");
printf("Enter a string: ");
scanf("%s",S);
printf("\nEnter the second string which you have to insert into string 1: ");
scanf("%s",T);
printf("\nEnter the location:");
scanf("%d",&N);
strinsert(N,S,T,U);
printf("\nThe string after inserting: %s",U);
}
void strinsert(int N,char S[20],char T[20],char U[20])
{
int i=0,j=0,a,b,slen,tlen;
while(S[i]!='\0')
{
i++;
}
while(T[j]!='\0')
{
j++;
}
slen=i;
tlen=j;
a=0;
b=0;
while(a<=slen){
U[a]=S[a];
a++;
}
while(b<=tlen){
U[a]=T[j];
a++;
j++;
b++;
}
while(S[N]!='\0'){
U[a]=S[N];
a++;
N++;
}
}