Thread: Structure of arrays

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    16

    Structure of arrays

    Hi,

    I have a structure of arrays such as:

    Code:
    typedef struct {
    	double array1[10];
    	double array2[10];
    	double array3[10];
    } data_array_struct;
    How do I access the elements of the arrays?

    I've tried to assign values using something like
    Code:
    data_array_struct.array1[i]=5;
    but the compilers says that there is "expected identifier or ‘(’ before ‘[’ token."

    Thanks!

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    "data_array_struct" is the name of the typedef. You need a real instance:
    Code:
    data_array_struct  example;
    example.array1[0] = 5.0;
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    16
    Oh great! That was the problem. Thanks for your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  2. help with structure arrays
    By mapunk in forum C Programming
    Replies: 8
    Last Post: 11-17-2005, 08:44 AM
  3. sorting a structure of arrays
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 03-15-2002, 11:45 AM
  4. displaying data from a structure of arrays
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 03-14-2002, 12:35 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM

Tags for this Thread