C/printf: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
m →‎Uwagi: asprintf
Linia 363:
 
{{TODO|Porównać ze standardem C89 i oznaczyć funkcjonalności wprowadzone dopiero w C99.}}
 
====Rozszerzenia GNU====
 
<source lang =c>
/*
 
Using asprintf instead of sprintf or snprintf by james :
"To use this function you also need to define _GNU_SOURCE on the gcc command line (of in the program with a define before the includes)"
http://www.stev.org/post/2012/02/10/Using-saprintf-instead-of-sprintf-or-snprintf.aspx
 
http://ubuntuforums.org/showthread.php?t=279801
 
gcc a.c -D_GNU_SOURCE -Wall // without #define _GNU_SOURCE
 
gcc a.c -Wall
 
*/
 
 
#define _GNU_SOURCE // asprintf
#include <stdio.h>
#include <stdlib.h>
int main() {
char *tmp = 0;
 
//
if (asprintf(&tmp, "%s %s %s", "Hello", "world", "here I am !") < 0) {
perror("asprintf");
exit(EXIT_FAILURE);
}
printf("%s\n", tmp);
free(tmp);
return 0;
}
</source>
 
===Zobacz też===