O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Arrays of Structures

Structures, just like integers, floats, and characters, can be used in arrays. The syntax for creating one is just like you'd expect:

struct students {
   char name[30];
   float gpa;
};
struct students class[20];

To refer to an individual array element, you would of course refer to the array's index, like class[19]. To refer to an individual structural member of an individual array element, the syntax is

					array_name[index].field_name
class[10].gpa = 2.78;

In our next example, we create a list of student names and grades by taking input from the user and storing it in an array of structures.

To use arrays of structures

1.
Create a new file or project in your text editor or IDE.
2.
Type the standard beginning lines of code ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required