Thread: structs

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    2

    structs

    Ok I am getting confused- laugh if you must! When you create a struct and you are reading in the information to the struct, say you need to read in 10 things, can you hold all within the one struct or do you need to pass it along to a "holding place"??

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    A structure is just a chunk of memory of certain size. You can't just 'automagically' store 10 structures in 1, no. Try using an array of structs, a linked list of them, etc.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    2
    ok I will try that thanks!!

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>say you need to read in 10 things, can you hold all within the one struct
    Yes, if you want to. This will give you one struct that holds 10 names:
    Code:
    struct foo
    {
      char Names[10][MAX_LEN_NAME];
    };
    
    struct foo bar;
    However, depending on how you're using the data, and how it's all related, you may need the array of structs as already mentioned.
    Code:
    struct foo
    {
      char Name[MAX_LEN_NAME];
    };
    
    struct foo bar[10];
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

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