dimanche 19 avril 2015

Accessing Embedded Linked Lists in C

Considering I have two structures. The first one represents a student :



typedef struct student

{
int code; // code of student
char* name;
note* list_note; // a list of his notes
struct* student next;

}


And the other one represents his notes :



typedef struct note

{

char* name // name of subject . eg:math
floate note // note at exam;
struct note* next;



}


The data file that contains information about students and their notes were stored on my computer and I was able to load them.


This is an example of the data file :



1300 david
programming 14
math 14
webmastering 18


Now I want to create a function that shows all the student who have all their notes higher than 12. I created the following code, that doesn't generate any error, but during execution it doesn't give me what I want.


Here is the code :



student* std=list_std;// list_std was declared in the functions that reads the data file and loads it;
note* nt=list_note;// list_note was declared in the functions that reads the data file and loads it;

while ( std)
{


while (nt )
{
if ( std->nt->note < 12)
{
break;
}
else
{
nt=nt->next
}
}

printf("%s",std->name);
std=std->next;
}

Aucun commentaire:

Enregistrer un commentaire