Solved

accessing an array of structures

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

Industry Leaders: 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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them 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.

691 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