Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. #include <string.h>
  5.  
  6. void *concat(int n,...)
  7. {
  8.     int i,size;
  9.     char *result;
  10.     char *list[n];
  11.     va_list ap;
  12.     va_start(ap,n);
  13.     size=0;
  14.     for(i=0; i<n; i++)
  15.     {
  16.         list[i]=va_arg(ap,char*);
  17.         if(list[i]!=NULL)
  18.         {
  19.             size=size+strlen(list[i]);
  20.         }
  21.     }
  22.     result=malloc(size+1);
  23.     result[0]='\0';
  24.     for(i=0; i<n;i++)
  25.     {
  26.         if(list[i]!=NULL)
  27.         {
  28.             result=strcat(result,list[i]);
  29.         }
  30.     }
  31.     va_end(ap);
  32.     return result;
  33. }
  34.  
  35. int main()
  36. {
  37.     char *resultat;
  38.     resultat=concat(3,"Ana ","si ","ion"); //varianta cu spatiu
  39.     puts(resultat);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement