Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-09-2009
Member
 
Join Date: Jun 2009
Posts: 441
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?
Reply With Quote
  #2  
Old 02-09-2009
Member
 
Join Date: May 2008
Posts: 3,514
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.
Reply With Quote
  #3  
Old 02-09-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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]);
Reply With Quote
  #4  
Old 02-09-2009
Member
 
Join Date: Nov 2008
Posts: 1,221
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);
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Getting warning message during compilation but not during execution"
Thread Thread Starter Forum Replies Last Post
Bios warning message on MSI Eclipse SLI P@poY!! Motherboard Processor & RAM 2 13-05-2012 10:25 AM
Norton 360 backup warning message again Tamas Networking & Security 6 22-09-2010 12:03 AM
Get 'Data Execution Prevention' warning in Internet Explorer 8 Anwar Technology & Internet 6 31-07-2009 02:47 AM
Warning Message : Error Code 1 Clemens Operating Systems 3 28-02-2009 06:29 PM
USB shows warning message JamesB Hardware Peripherals 4 26-02-2009 06:32 PM


All times are GMT +5.5. The time now is 01:59 AM.