#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char *s1, *s2, *s3;
int length, len1=0,len2=0, i, j;
clrscr();
s1=(char*)malloc(20* sizeof(s1));
s2=(char*)malloc(20* sizeof(s2));
printf("Enter first string\n");
gets(s1);
len1=strlen(s1);
printf("Enter second string\n");
gets(s2);
len2=strlen(s2);
length=len1+len2;
s3= (char*)malloc((length+2)* sizeof(s3));
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); /* copying 2nd string */
++i;
}
*(s3+i)='\0'; /* store '\0' at end to set 'end of string' */
printf("Concatenated string is\n%s", s3);
getch();
}
Can you please point out the errors in this code, which is used to concatenate two strings... it is showing too many errors first its asking for a prototype for malloc function..