how can i aggregate text from different sources for example
char * a , * b,* c, *d;
a = argv[1] ;
b = "something";
c = "another text";
d=b&a&c; //this what i want to know
printf("%s",d);
output :
somethingTESTanother text
how can i aggregate text from different sources for example
char * a , * b,* c, *d;
a = argv[1] ;
b = "something";
c = "another text";
d=b&a&c; //this what i want to know
printf("%s",d);
output :
somethingTESTanother text
First you need to get some memory for saving the resulting string.
You can allocate just enough memory using malloc()
; or (easier but does not scale) define d
as an array with enough space (eg char d[8000];
).
Then, after you have space for the result, you can strcpy()
and strcat()
; or sprintf()
(if using C99 prefer snprintf()
); or a number of other ways.
char *a, *b, *c, *d;
a = argv[1];
b = "something";
c = "another text";
int n = snprintf(NULL, 0, "%s%s%s", a, b, c);
d = malloc(n + 1);
if (!d) /* error */ exit(EXIT_FAILURE);
snprintf(d, n + 1, "%s%s%s", a, b, c); //this what i want to know
printf("%s\n",d);
free(d);