1. S1-4
#include<stdio.h>
#include<conio.h>
Write a program to concatenate two strings S1 and S2.
#include<string.h>
void main()
{
char *s1, *s2, *s3;
int len, len1,len2, i, j;
clrscr();
s1=(char*)malloc(20);
s2=(char*)malloc(20);
printf("Enter first stringn");
gets(s1);
len1=strlen(s1);
printf("Enter second stringn");
gets(s2);
len2=strlen(s2);
len=len1+len2;
s3= (char*)malloc(len+2);
for(i=0;i<len1;++i)
*(s3+i) =*(s1+i);
*(s3+i)=' '; /*leave a space at end of first string */
++i;
for(j=0;j<len2;++j)
{ *(s3+i)=*(s2+j);
++i;
}
*(s3+i)='0'; /* store '0' at end to set 'end of string' */
printf("Concatenated string isn%s", s3);
getch();
}
Page 1