Arrays of Structs
Just like any other datatype in C, you can also create arrays of structs.
To do this, the syntax is the same as any other array you may want to
declare. Let's say we declare the following:
typedef int GRADE;
typedef struct grades {
GRADE midterm, final,
proj1, proj2;
float courseAverage;
} GRADES;
If we wanted to deal with all the students in a given class in one program,
we could declare an array of structs, one element of the array will hold
the grades for one student. Kind of convenient. *smile*
To declare the array we would type the following:
GRADES cmsc201[650];
Note: The above declaration would inevitably take a very large amount of
memory to create and be unweldy, but you get the idea...
In order to access the elements of our struct array, we would do something
along these lines:
cmsc201[456].midterm
cmsc201[i].final
Any questions???
Main Page
:
Last Modified 24 October 2000