I'm creating a program using C, and I have this line in my code :
scanf("%s", &path);
When I compile the source file, I get this warning :
main.c:84:2: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[64]’ [-Wformat]
And this is the declaration for the path variable :
char path[64];
Why I'm seeing this error? And how can I solve it ?
An array is already a pointer-like object (as dreamlax points out). You don't need the & operator, since declaring
char path[64];
is equivalent to setting path to a pointer to a 64-byte region of memory.
The %s format specifier requires you to supply a char *, which is a pointer to char. You are passing &path, which is a pointer to an array. You can just pass path by itself, which will evaluate to a pointer to the first element of the array (the same as &path[0]).
try this scanf("%s", path); instead because I think path is an array and a pointer to an array is the array name itself ( array == &array )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With