format '%s' expects type 'char *', but argument 3 has type 'char (*)[31]'
Hello,
My c code complied OK and run well on UNIX. But on Linux , it reported a warning while compiling . Code:
Can anybody tell me why ? it is ok in UNIX . Thanks. Ray |
To start off with please use code tags!
The warning says what it is the printf statement is expecteing a pointer to a sring of characters ( char* ) where as you are fiving it a pointer to a an array of 31 characters, char* is a zero terminated pointer to a string your array may not be, any way to remove the warning just type cast the pointer ie: Code:
printf ( "%s\n",(char*)tempstr); |
In addition to Keith's comment.
This doesn't mean that your code is OK in Unix, it means that the compiler you used on Unix sucks. Cheers, Tink |
You may have altered your code between compilation and publication:
Code:
good: char chararray[10]; printf ("%s", chararray); |
Depending on the default settings for the compiler this would still flag up a warning.
|
Code:
Typed char varname[31]; Code:
Char tempstr[31]; Code:
sprintf(tempstr, ", %s[%s]",bind +i,outidx); My earlier points are that "Typed" and "Char" are not native (IMHO) C terms, I believe native terms would be "typedef" and "char" (lowercase 'c'). If there are other preprocessor files which give you these abstractions, fine. Just beware of them. And I can't really think of a reason why someone would want to have "Typed" for any real reason. Especially since it only saves you about one keystroke. You have two fewer characters in the name, but you had to shift to type one of those characters. I do get that things like Char are available in the more modern IDEs like Visual Studio or Eclipse. Jus tnot sure yet I agree. |
Quote:
|
Here's my current flags that I typically use.
-Wall doesn't get them all Funny, you learn alot about your coding style once you start paying more detailed attention. And these are by no means the best, they just happen to be useful to me: Code:
CFLAGS += -Wformat=2 -Werror -Wall -Wextra -Wswitch-default -Wswitch-enum -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn |
All times are GMT -5. The time now is 01:21 AM. |