Thread: structs

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005


    Hey guys just wondering if there is a simple way to allocate memory for each
    pointer in my loadData function from the structs in my .h file.

    int loadData(GJCType* menu, char* menuFile, char* submenuFile)
    typedef struct category* CategoryTypePtr;
    typedef struct item* ItemTypePtr;
    /* Structure definitions. */
    typedef struct price
       unsigned dollars;
       unsigned cents;
    } PriceType;
    typedef struct item
       char itemID[ID_LEN + 1];
       char itemName[MAX_NAME_LEN + 1];
       PriceType prices[NUM_PRICES];
       char itemDescription[MAX_DESC_LEN];
       ItemTypePtr nextItem;
    } ItemType;
    typedef struct category
       char categoryID[ID_LEN + 1];
       char categoryName[MAX_NAME_LEN + 1];
       char drinkType;      /* (H)ot or (C)old. */
       char categoryDescription[MAX_DESC_LEN];
       CategoryTypePtr nextCategory;
       ItemTypePtr headItem;
       unsigned numItems;
    } CategoryType;
    typedef struct gjc
       CategoryTypePtr headCategory;
       unsigned numCategories;
    } GJCType;

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Given this:
    int loadData(GJCType* menu, char* menuFile, char* submenuFile)
    It doesn't matter if you try to allocate memory or not. These are just local copies.

    [criticism type="constructive" level="poor"]
    Mentally I've attached your user name to "Mr. Seg Fault". You seem to not only be playing 20 questions, but 20 threads. Is it possible that you can post a reasonably-sized snippet of an actual [single-module (because then it would be easier for at least me to play along)] bit of code that demonstrates your actual problem?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating array of structs
    By knirirr in forum C++ Programming
    Replies: 12
    Last Post: 06-18-2008, 08:30 AM
  2. Multidimentional structs + memcpy() == FAIL
    By Viper187 in forum C Programming
    Replies: 8
    Last Post: 06-18-2008, 02:46 AM
  3. packed structs
    By moi in forum C Programming
    Replies: 4
    Last Post: 08-20-2002, 01:46 PM
  4. ArrayLists + Inner Structs
    By ginoitalo in forum C# Programming
    Replies: 5
    Last Post: 05-09-2002, 05:09 AM
  5. Searching structs...
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 08-25-2001, 12:38 PM