The function fgets
can append to the entered string the new line character '\n'
. So the function strlen
counts this new line character.
From the C Standard (7.21.7.2 The fgets function)
2 The fgets function reads at most one less than the number of
characters specified by n from the stream pointed to by stream into
the array pointed to by s. No additional characters are read after a
new-line character (which is retained) or after end-of-file. A
null character is written immediately after the last character read
into the array.
To remove the new line character from the string you can write
name[ strcspn( name, "\n" ) ] = '\0';
After that you can call the function printf
using the conversion specifier zu
instead of d
(otherwise the call has undefined behavior).
printf("length is : %zu\n", strlen(name));