Thread: C Structures...HELP

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    C Structures...HELP

    Why doesn't this work?

    I have a main "struct CatRec" Structure. Each Cat can have several Kittens,so i created a structure for the kittens...so now each CAt can have a maximum of 20 Kittens...but this doesn't work. C doesn't accept the [20] Array. PLEASE HELP!


    Code:
    // STRUCTURES
    struct KittenRec {
       int kittennum;             // Kitten Number
       char kittenname[10];       // Kitten Name
       char kittenParentName[10]; // Kitten ParentName
       int kittenParentNum;       // Kitten ParentNum
       char type[20];             // Type of Kitten
       char genuine;              // Genuine Breed
       char color[10];            // The Color of the Kitten
    };
    
    struct CatRec {
       int catnum;
       char catname[10];  // Cat Name
       char gender;       // The Gender of the Cat: M,F
       char type[20];     // Type of Cat
       char color[10];    // The Color of the Cat
       int  age;          // Age of Cat
       char genuine;      // Genuine Breed
       float sellingprise;
       int medalswon;
       float income;
       struct KittenRec Kittens[20];
    };

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Seems OK here
    Perhaps you should post an actual error message as well
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    try

    struct CatRec {
    KittenRec Kittens[20]; //not struct KittenRec Kittens[20];
    };

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > KittenRec Kittens[20]; //not struct KittenRec Kittens[20];
    Because that is either C++, or you missed out
    typedef struct KittenRec KittenRec;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    i missed out

    ........

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  3. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 08:00 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM