Format '% s expects an argument of type char *, but argument 2 is of type' char (*) [64]

I am 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 ‘%sexpects argument of typechar *’, but argument 2 has typechar (*)[64][-Wformat]

And this is the declaration for the variable path:

char path[64];

Why am I seeing this error? And how can I solve it?

+4
source share
3 answers

The array is already a pointer object (as indicated by a dream pointer). You do not need an operator &, since the announcement

char path[64];

equivalent to setting a pathpointer to a 64-byte memory area.

+5
source

%s , char *, char. &path, . path , ( , &path[0]).

+4

scanf("%s", path);, , path - , - (array == & array)

+1
source

All Articles