Thread: whats wrong with this

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    15

    whats wrong with this

    Hi, Can someone please enlighten me as to what is wrong with this code.
    Code:
    #include<stdio.h>
    int main()
    {
    
    struct virus{
    char signature[25];
    char status[25];
    int size;
    }v[2]={
    "Yankee Doodle","Deadly",1813,
    "Dark Avenger","Killer",1795
    };
    int i;
    for(i=0;i<2;i++){
    printf("\n&#37;s %s\n\n",v.signature,v.status);
    }
    return 0;
    }
    Output:
    Code:
    gcc -Wall c.c -o c
    c.c: In function ‘main’:
    c.c:10: warning: missing braces around initializer
    c.c:10: warning: (near initialization for ‘v[0]’)
    c.c:15: error: request for member ‘signature’ in something not a structure or union
    c.c:15: error: request for member ‘status’ in something not a structure or union
    Last edited by Salem; 08-18-2008 at 03:00 PM. Reason: Restored, so others may learn something in future

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Not initializing vars right, also there is no array indice when you are attempting to display the array back.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Exactly what the compiler says:
    Code:
    request for member ‘signature’ in something not a structure or union
    refers to the fact that v.signature is trying to get something called signature out of an array of struct virus v[2].

    It is also correct that:
    Code:
    missing braces around initializer
    Edit: I suppose since the OP removed all the content of his/her post, we could delete this thread, as it's pretty meaningless by now.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    you don't include the array reference in line 15, which should be:
    Code:
    printf("\n%s %s\n\n",v[i].signature,v[i].status);
    witness the use of [i].
    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. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM