How do I construct a "signed size_t" for use with scanf("%zn")?
I tried to obtain the number of characters read as a size_t, using this program:¹ #include <stdio.h> int main(void) { size_t i; sscanf("abc", "%*s%zn", &i); printf("%zu", i); } GCC 12 warns about this: scanf.c: In function ‘main’: scanf.c:7:25: warning: format ‘%zn’ expects argument of type ‘signed size_t *’, but argument 3 has type ‘size_t *’ {aka ‘long unsigned int *’} [-Wformat=] 7 | sscanf("abc", "%*s%zn", &i); | ~~^ ~~ | | | | | size_t * {aka long unsigned int *} | long int * | %ln And it's correct² do do so; in the C17 draft standard, page 234, we read (my emphasis) No input is consumed.
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.