Skip to content

Commit a9d1675

Browse files
authored
Create 6.c
1 parent 7fd2fcb commit a9d1675

File tree

1 file changed

+46
-0
lines changed
  • Special Programs

1 file changed

+46
-0
lines changed

Special Programs/6.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//Write a C function to concatenate two strings passed using pointers.
2+
3+
#include<stdio.h>
4+
int length(char *s)
5+
{
6+
int i=0;
7+
while(*(s+i)!='\0')
8+
{
9+
i++;
10+
}
11+
return i;
12+
}
13+
void concatenate(char *s,char *s1,char *s2,int len,int len1)
14+
{
15+
int i,j=0;
16+
for(i=0;i<=(len+len1);i++)
17+
{
18+
if(i<len)
19+
{
20+
*(s2+i)=*(s+i);
21+
}
22+
else if(i==len)
23+
{
24+
*(s2+i)=' ';
25+
}
26+
else
27+
{
28+
*(s2+i)=*(s1+j);
29+
j++;
30+
}
31+
}
32+
*(s2+i)='\0';
33+
}
34+
void main()
35+
{
36+
char s[100],s1[100],s2[200];
37+
int len,len1;
38+
puts("Enter the 1st string ");
39+
gets(s);
40+
puts("Enter the 2nd string ");
41+
gets(s1);
42+
len=length(s);
43+
len1=length(s1);
44+
concatenate(s,s1,s2,len,len1);
45+
puts(s2);
46+
}

0 commit comments

Comments
 (0)