3 ms·
char x[44]; sprintf(x, "%d %d", i, i); This is fine, except you can't even return x from this function, a more fair comparison might be: char * x = m
by onedognight 15y ago
char x[44];
sprintf(x, "%d %d", i, i);
This is fine, except you can't even return x from this function, a more fair comparison might be:
char * x = malloc(44 * sizeof(char));
sprintf(x, "%d %d", i, i);*
There is a standard (C99) way to do this: asprintf(3).
char *x;
asprintf(&x, "%d %d", i, i);
return x;
- tedunangst 15y agoThere is no asprintf function in my copy of the C99 standard.
- onedognight 15y agoSorry, you are correct; I mis-read the man page. It is however in at least glibc and Darwin/FreeBSD's libc.
- supersillyus 15y agoasprintf is a GNU extension, I believe.