#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct module {
char name[10];
int note;
struct module * next;
};
typedef struct module module;
struct student {
char name[10];
char adress[20];
struct student * next;
module * head;
} ;
typedef struct student student;
student *etudiant=NULL;
module* add_module(char name[],int note){
module *p=(module*)malloc(sizeof(module));
p->note=note;
p->next=NULL;
strcpy(p->name,name);
return p;
}
void add_student(char name[], char adress[])
{
student *p=(student*)malloc(sizeof(student));
strcpy(p->name,name);
strcpy(p->adress,adress);
p->head= add_module("algo",15);
p->next=NULL;
if (etudiant==NULL){
etudiant=p;
}
else{
student *q = etudiant;
while(q->next!=NULL){
q=q->next;
}
q->next=p;
}
}
void print_module(module *m){
if (m==NULL)
{
printf("NULL");
}
else
{
while(m->next!=NULL){
printf("%s ",m->name);
printf("%d\n",m->note);
m=m->next;
}
}
}
void print(){
student *p;
module *m;
p = etudiant;
if (etudiant==NULL){
printf("NULL");
}
else
{
while (p->next!=NULL);
{
printf("%s ",etudiant->name);
printf("%s ",etudiant->adress);
m = p->head;
while(m != NULL){
printf("%s ",m->name);
printf("%d ",m->note);
m= m->next;
}
p = p->next;
}
}
}
int main () {
add_student("jack","nowhere");
print();
return 0;
}
What I want to create is a list inside a list exemple
Student list :
Student || subject || ==> student 2 || subject
| |
maths POO
| |
physiques English
that's an approximate paiting of my structure, i arrived to add one subject to one student, but i don't know how to add more. thanks in advance.
I defined the student list as a global one since i would be needing only one list containing all students