Thread: initializing struct values

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    164

    Question initializing struct values

    ok, obviously since an array or array of struct are initiated in RAM, I can not initialize my int variables to 0. Is there a default value issued in RAM that I can look for to begin counter values so I know how it add to ints?

    The only way I could think to do it is, at the first initial pass of the program create a do loop to intialize every index of my 2d array so that all of my struct int variables get set to 0.

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    164
    Nevermind, I found the answer in my books, sorry for the post!

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Don't be sorry.....

    And the answer is.........?

    gg

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    164
    I can initialize my struct as long as it is not within the declaration. I still used a loop to do all my values, but I could not find anything within my books that made it less difficult. But they are begginer books....

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    if your looking to initialize everything to zero, you might consider the "memset()" function.

  6. #6
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    You could initialize everything in a struct when it's declared....sometimes
    Code:
    struct Obj
    {
       int a;
       short b;
    };
    
    Obj temp =  {0, 0};

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-07-2009, 08:49 AM
  2. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  3. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  4. Concatenating in linked list
    By drater in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 11:10 PM
  5. Replies: 10
    Last Post: 05-18-2006, 11:23 PM