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>
- char *concat(int n, ...) {
- va_list al;
- va_start(al, n);
- int len = 1;
- char *res = calloc(sizeof(char), n);
- for (int i = 0; i < n; i++) {
- char *s = va_arg(al, char*);
- len += strlen(s) + 1;
- res = realloc(res, sizeof(char) * len);
- strcat(res, s);
- strcat(res, " ");
- }
- va_end(al);
- return res;
- }
- int main(void) {
- char *res = concat(3, "asd", "qwerty", "6543210");
- puts(res);
- free(res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement