Doubt about char in C

This is a discussion on Doubt about char in C within the C Programming forums, part of the General Programming Boards category; Hi, Code: #include<stdio.h> struct an { int num; char name[256]; }a; char *match = "This is a test: 10 ok"; ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    2

    Lightbulb Doubt about char in C

    Hi,

    Code:
    #include<stdio.h>
    
    struct an
    {
     int num;
     char name[256];
    }a;
    
    char *match = "This is a test: 10 ok";
    
    int main(void) {
    sscanf(match, "This is a test: %d %s", &a.num, &a.name);
    printf("%d\n%s\n", a.num, a.name);
    return 0;
    }
    When I compile the above program I am getting the below warning.

    Code:
    t1.c: In function ‘main’:
    t1.c:13: warning: format ‘%s’ expects type ‘char *’, but argument 4 has type ‘char (*)[256]’
    why I am getting this warning, I tried removing the size of char name but printf throwing similar warning, what is causing this warning and how to clear this warning?


    Thanks in advance,
    Alagunambi Welkin

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    2
    I am using gcc

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    The name of an array is used as a pointer to it's first element, so you shouldn't be using the & (address of) operator with it -- that will give you a pointer to a pointer.

    Ie, just lose the & with a.name
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 08:36 AM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 10:22 AM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21