Home › Forums › C Programming › How to redo the same code using structs › Re: Re: How to redo the same code using structs
July 27, 2009 at 7:00 pm
#3598
Participant
A little correction. It seems you are passing arrays of names , id’s and crn into the function:
1 2 3 | <br /> void addStudent (char name[SIZE][LENGTH], int id[SIZE], int crn[SIZE][4]);<br /> |
so you would change your prototype to :
1 2 3 4 | <br /> const int numberOfStudents = 20; //whatever<br /> void addStudent ( STUDENT newStudent [ numberOfStudents ] );<br /> |
and access the data members like this:
1 2 3 4 5 6 7 | <br /> ..........<br /> int i = currentStudent;<br /> printf ( newStudent [ currentStudent ].name ); //output the student name<br /> printf ( "%i" , newStudent [ currentStudent ] .id ); //output the student id<br /> <br /> |
my bad ………