[ create a new paste ] login | about

Link: http://codepad.org/81ept4pp    [ raw code | output | fork ]

kamarakay2000 - C, pasted on Aug 12:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <string.h>
char *longer(char *s1, char *s2)
{
char *result = malloc(strlen(s1) + strlen(s2) + 1); 
//combine the strings
strcpy(result, s1);
strcat(result, s2);
return result;
}

int main()
{
char *string1 = "A long time ago  ";
char *string2 = "in a glaxy far far away";
char *result;
result = longer(string1, string2);
printf("'%s'\n",result);

return(0);
}


Output:
1
'A long time ago  in a glaxy far far away'


Create a new paste based on this one


Comments: