Solved

accessing an array of structures

Posted on 2003-11-29
1
258 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
1 Comment
 
LVL 19

Accepted Solution

by:
Dexstar earned 250 total points
Comment Utility
@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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now