a data array where each element has two values, not just one?

This is a discussion on a data array where each element has two values, not just one? within the C Programming forums, part of the General Programming Boards category; Hi. New here. Not new to C programming but have never gone much deeper than the basics. I have worked ...

  1. #1
    HAL
    HAL is offline
    Registered User
    Join Date
    Aug 2012
    Posts
    2

    a data array where each element has two values, not just one?

    Hi. New here. Not new to C programming but have never gone much deeper than the basics.

    I have worked with data arrays for embedded DSP algorithms, and although some of them have been of two or three or more dimensions, up until now all these arrays have had a single data value per element. [i hope i am using the correct terms...]

    Now i am working on an algorithm that seems to need two dimensions and two data values that need to change independently, per element.
    I'm not sure how to go about this.

    I have looked over the tutorials, but so far i haven't found this subject discussed.
    Is this easy to do?
    Is this going to be possible with arrays or will i need to move up to pointers?
    Is this covered in the tutorials somewhere? If not, please advise. Thanks.

    Regards,

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Sounds like you're looking for an array of structs.
    Code:
    #include <stdio.h>
    
    #define XSIZE 10
    #define YSIZE 10
    
    struct Element {
        int m;
        int n;
    };
    
    int main(void) {
        struct Element a[YSIZE][XSIZE];
        a[0][0].m = 1;
        a[0][0].n = 2;
        printf("%d %d\n", a[0][0].m, a[0][0].n);
        return 0;
    }
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    HAL
    HAL is offline
    Registered User
    Join Date
    Aug 2012
    Posts
    2

    Thumbs up

    Hi oogabooga! Thanks for the quick response. This looks like just what i need. Structures - awesome! Thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 02-10-2012, 05:42 AM
  2. size of an array poited by array element
    By mitofik in forum C Programming
    Replies: 7
    Last Post: 12-24-2010, 12:09 AM
  3. data structure element
    By aayu09 in forum C Programming
    Replies: 1
    Last Post: 03-31-2010, 09:53 PM
  4. dynamic array and losing data of the first element
    By fx69 in forum C++ Programming
    Replies: 9
    Last Post: 02-25-2010, 05:15 AM
  5. Accessing a data element in a function
    By Zooker in forum C Programming
    Replies: 5
    Last Post: 02-05-2009, 04:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21