Results 1 to 4 of 4

Thread: Getting warning message during compilation but not during execution

  1. #1
    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?

  2. #2
    Join Date
    May 2008
    Posts
    3,516

    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.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    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]);

  4. #4
    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);

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,857,710.60151 seconds with 16 queries