Thread: Arrays with structs?

  1. #1
    Registered User
    Join Date
    Feb 2010

    Arrays with structs?

    I have A[ROW][COL] which holds a value of either true or false, so 1 or 0, how would I also be able to hold another value next to this that can vary? How would I do this with structs?

    so if A[1][2]=1 and then I want to hold the sum value of 3, somewhere I can recall it, how would I do this?

    Would I have to do like A[1][2].sum=3.

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    You are on the right track. You have to define the struct first, then make an array of it.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    London, United Kingdom
    What you want is something like this:

    struct X{
      int flag;
      int sum;
    /* make an array of X's */
    struct X[10];
    int i;
    for(i = 0;i < 10;i++){
       X[i].flag = 1;
       X[i].sum = 3;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with 2-D arrays and structs
    By dearbear in forum C Programming
    Replies: 5
    Last Post: 12-11-2009, 03:28 PM
  2. allocatable arrays in CLASSes and STRUCTS
    By simone.marras in forum C++ Programming
    Replies: 4
    Last Post: 03-14-2009, 10:50 AM
  3. a question on pointers, structs and arrays
    By onefootswill in forum C Programming
    Replies: 3
    Last Post: 12-06-2007, 01:27 AM
  4. HELP with structs that contain arrays
    By koolrud in forum C Programming
    Replies: 1
    Last Post: 06-08-2006, 05:56 PM
  5. malloc for structs and arrays
    By rkooij in forum C Programming
    Replies: 15
    Last Post: 05-04-2006, 07:38 AM