Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <string.h>
- void *concat(int n,...)
- {
- int i,size;
- char *result;
- char *list[n];
- va_list ap;
- va_start(ap,n);
- size=0;
- for(i=0; i<n; i++)
- {
- list[i]=va_arg(ap,char*);
- if(list[i]!=NULL)
- {
- size=size+strlen(list[i]);
- }
- }
- result=malloc(size+1);
- result[0]='\0';
- for(i=0; i<n;i++)
- {
- if(list[i]!=NULL)
- {
- result=strcat(result,list[i]);
- }
- }
- va_end(ap);
- return result;
- }
- int main()
- {
- char *resultat;
- resultat=concat(3,"Ana ","si ","ion"); //varianta cu spatiu
- puts(resultat);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement