format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ [-Wformat]
Did you check the man page? strlen(3)
returns size_t
. Use %zu
to print it.
As mentioned in the comments below, clang is sometimes helpful with finding better error messages. clang's warning for exactly this case is pretty great, in fact:
example.c:6:14: warning: format specifies type 'unsigned int' but the argument
has type 'size_t' (aka 'unsigned long') [-Wformat]
printf("%u\n", strlen("abcde"));
~^ ~~~~~~~~~~~~~~~
%zu
1 warning generated.