Hello.
I'm playing around with C and strings.
This is piece of code inside main function:
Code:
char *format;
fscanf(fstream, "%2s", format);
fprintf(stdout, "%s\n", &format);
This is what compiler (gcc) spits out when fprintf uses '&' annotation before string variable:
Code:
string_test.c: In function ‘main’:
string_test.c:23:5: error: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘char **’ [-Werror=format=]
fprintf(stdout, "%s\n", &format);
^
cc1: all warnings being treated as errors
And this is what compiler spits out when fprintf ommits the '&':
Code:
string_test.c: In function ‘main’:
string_test.c:21:11: error: ‘format’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
fscanf(fstream, "%2s", format);
^
cc1: all warnings being treated as errors
What am I supposed to write there then?