Advertisement
alexarcan

Copy a string to the end of a string

Feb 14th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<ctype.h>
  4. #include<stdlib.h>
  5.  
  6. typedef struct
  7. {
  8.  
  9.   unsigned argc;
  10.   char *args;
  11.  
  12. }func_t;
  13.  
  14. func_t concat( func_t s1 ,char s[])
  15. {
  16.   s1.args=realloc(s1.args, s1.argc+strlen(s));
  17.   strcpy(s1.args+s1.argc,s);
  18.   s1.argc=strlen(s1.args);
  19.  
  20.   return s1;
  21. }
  22.  
  23.  
  24.  
  25. int main(void)
  26. {
  27.  char s[20]="Gummybear";
  28.  func_t s1={0, NULL};
  29.  
  30.  s1=concat(s1,s);
  31.  printf("%s \n",s1.args);
  32.  
  33.  s1=concat(s1,"SSS");
  34.  printf("%s \n",s1.args);
  35.  
  36.  
  37.  putchar('\n');
  38.  
  39.  return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement