1.5.24: gcc / libc problem with sscanf
Tue Apr 17 15:17:00 GMT 2007
Matteo Corti wrote:
> I get strange results when using the %zi flag for the sscanf and fscanf
> The following code scans a line and parses an integer and a size_t value.
> size_t var_size_t = 0;
> int var_int = 0;
> char * string = "2 10";
> sscanf(string, "%zi %i\n", &var_size_t, &var_int);
> printf("size_t = %zi\n", var_size_t);
> printf("int = %i\n", var_int);
> The code when compiled and run generates 2 followed by 0 instead of the
> correct 2 and 10 (that I get on linux and mac os x).
Yes, unfortunately newlib does not support the 'z' size flag for the
scanf family of functions. It's got nothing to do with gcc or Cygwin
directly, we just inherit whatever functionality newlib has, as that's
where all the stdio implementation comes from.
>From what I can tell this is a C99 item that wasn't in POSIX/SUSv3/ANSI
C/C90, so it's no surprise that it's not implemented as widely. I think
Eric Blake has been recently working on getting more C99 printf/scanf
specifiers implemented in newlib, so there's a chance this is on his
TODO list, but no guarantees.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
More information about the Cygwin