Getting warning message during compilation but not during execution
I am having problem compiling my following program:
Code:
# include <stdio.h>
int main()
{
char x[]="Amar",y[]="Akbar",z[]="Anthony";
printf ("%u\n",x);
printf ("%u\n",&y[0]);
printf ("%u\n",&z[0]);
}
It gives me a lot of error messages such as "format ‘%u’ expects type ‘unsigned int’, but argument 2 has type ‘char *’" and the same thing goes for the other two lines. Why I am getting this kind of messages? I have also seen that this message doesn't appear when I run the program. Then why I am getting this warning message only during compilation and not during the execution?
Re: Getting warning message during compilation but not during execution
You are getting that warning message only because of "%u" which is used for "unsigned int". Use "%s" instead to avoid this warning message. The compiler is telling you that you are using "%u" although you are passing characters. Also one more thing, this kind of warning messages are left unconsidered during execution and so you are not getting the warning messages at the time of execution.
Re: Getting warning message during compilation but not during execution
What are you trying to print? If you want addresses of that variables then use "&" and if not then use "%c" or "%s" as below:
Code:
printf ("%c\n",&x);
printf ("%c\n",&y[0]);
printf ("%c\n",&z[0]);
OR
Code:
printf ("%s\n",x);
printf ("%s\n",y[0]);
printf ("%s\n",z[0]);
Re: Getting warning message during compilation but not during execution
I suppose you are trying to print variables addresses in decimal format rather than displaying them in hexadecimal format. If this is the case then I would recommend you should use typecasting as below:
Code:
printf("%llu",(unsigned long long)variable_name);