Good afternoon!
I need to use malloc to create a student list system ... To be effective, our professor asked us to use it in the structure, so I created the structure as follows:
struct student {
char studentID[6];
char name[31];
char course [6];
};
struct student *array[30];
every time I add a record, that is, when I use malloc ...
array[recordCtr]=(struct student*)malloc(sizeof(struct student));
recordCtr++;
then I will free him like that.
for(i = 0; i < recordCtr; i++){
free(array[i]);
}
Am I using malloc correctly ??? what is the effect if i release it like this instead of the loop above.
free(array);
Thanks in advance. Your feedback will be highly appreciated.
source
share