-
structure question
I have this structure set up to answer a question to set up a structure which has a fix no of students, I think this is right, then comes the second part,
<CODE>
#include <stdio.h>
#define MAX_stud 100
struct student
{
char fName[20];
char sName[20];
char coursecode[3];
char feespaid[3];
int mark[3];
};
struct student studall [MAX_stud];
main()
{
}
<CODE>
The seccond part says that I have to make another structure in C to hold the same info but that the no of students changes. Not sure how to go about this, can you help?
-
Hmmm...
You should use dynamic memory allocation (linked lists) and you won't have to use #define MAX_stud 100 at all :)
-
He says that he has a fixed number of students. In this case it is more efficient to use an array or contiguous list, rather than a linked list.
-
struct?
I want to know how to do this without a fixed No I think that the struct that I have works for a fixed no. (correct me if I am wrong) but my knowledge of linked lists is not very good and have been messing around with them now for a few hours, not getting anywhere fast. It seams to me that these are good for adding in elements but I already know my fixed no of elements them being :
char fName[20];
char sName[20];
char coursecode[3];
char feespaid[3];
int mark[3];
It is a variable no of students that I have to cater for???
-
>It is a variable no of students that I have to cater for???
Multiple students == Multiple structs. Therefore you need to either use an array(fixed size), dymanic array, link list, binary search tree etc etc. Read up about them, pick one and write some code. Post here when you have problems. :)
-
>Multiple students == Multiple structs.
Correction, multiple students == multiple struct instances. Which screams linked data structure to me. But without more code, we can't really help you much since linked lists tend to be a difficult topic for new people and a specific question is easier to answer than trying to post the whole of linked list theory.
-Prelude