all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
25
Task/String-concatenation/C/string-concatenation.c
Normal file
25
Task/String-concatenation/C/string-concatenation.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *sconcat(const char *s1, const char *s2)
|
||||
{
|
||||
char *s0 = malloc(strlen(s1)+strlen(s2)+1);
|
||||
strcpy(s0, s1);
|
||||
strcat(s0, s2);
|
||||
return s0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char *s = "hello";
|
||||
char *s2;
|
||||
|
||||
printf("%s literal\n", s);
|
||||
/* or */
|
||||
printf("%s%s\n", s, " literal");
|
||||
|
||||
s2 = sconcat(s, " literal");
|
||||
puts(s2);
|
||||
free(s2);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue