Solved

accessing an array of structures

Posted on 2003-11-29
1
267 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 250 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

Suggested Solutions

Title # Comments Views Activity
Console based application in Linux 1 104
Problem to ASCII 1 233
Windows Server 2008 R2: %HOMEDRIVE%%HOMEPATH% Incorrect 4 89
Windows 10 14 30
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…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

739 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