?
Solved

accessing an array of structures

Posted on 2003-11-29
1
Medium Priority
?
270 Views
Last Modified: 2010-04-15
let's say I declare a data type the following way:
typedef struct DataGroup
{
  int element1;
  char element2[20];
};

Now I would like to declare a type that consists of an array with DataGroup structs. Something like:

typedef struct TestArray
{
  DataGroup element3[10];
};

struct TestArray myTestData;

I have trouble though with the correct syntax. How can I access element1 and element2[] from within myTestData and assign a value to these elements? Please also let me know if there is an easier or better way to do what I describe above. Important is that I have an array of DataGroup.
0
Comment
Question by:MikeJ2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 19

Accepted Solution

by:
Dexstar earned 1000 total points
ID: 9844259
@MikeJ2001:

> I have trouble though with the correct syntax. How can I access element1 and
> element2[] from within myTestData and assign a value to these elements? Please
> also let me know if there is an easier or better way to do what I describe
> above. Important is that I have an array of DataGroup.

Like this:
   myTestData.element3[0].element1 = 0;
   myTestData.element3[0].element2[0] = 0;
   myTestData.element3[1].element1 = 0;
   myTestData.element3[1].element2[3] = 0;

Hope That Helps,
Dex*
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question