Probleme d'un pointeur qui pointe sur une structure

Fermé
badsad Messages postés 1 Date d'inscription mardi 7 janvier 2014 Statut Membre Dernière intervention 7 janvier 2014 - 7 janv. 2014 à 20:54
bonjour!! j'ai un devoir a rendre .c'est un exercice qui fait la lecture d'une liste des élèves avec les listes linéaire chainée .mais ça ne fonctionne pas .Merci d'avance .voici le code source:
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
struct adresse
{
char rue[10];
char ville[10];
unsigned int cod_pos;
};
struct etudiant
{
char nom[10];
char prenom[10];
unsigned int age;
struct adresse adr;
float note1;
float note2;
float note3;
float moy;
int rang;
};
struct noeud
{
struct etudiant etud;
struct noeud *lien;
}*l;
float coef1,coef2,coef3;
void lecture(struct noeud **l,int nb);
/*********************************************************************/
void main()
{
int nb;
printf("\n donner le coef de la matiere 1: ");
scanf("%f",&coef1);
printf("\n donner le coef de la matiere 2: ");
scanf("%f",&coef2);
printf("\n donner le coef de la matiere 3: ");
scanf("%f",&coef3);
printf("Entrer le nombre des etudiants: ");
scanf("%d",&nb);
lecture(&l,nb);
}
/*********************************************************************/
void lecture(struct noeud **l,int nb)
{
int i;
struct noeud *p;
l=NULL;
printf("\nDoneer les informations des etudiants:");
for(i=1;i<=nb;i++)
{
p=(struct noeud*)malloc(sizeof(struct noeud));
printf("\nDnner les infrmations de etudiant %d: ",i);
printf("\nNom: ");
fflush(stdin);
gets(p->etud.nom);
fflush(stdin);
printf("\nPrenom: ");gets(p->etud.prenom);
fflush(stdin);
printf("\nAge: ");scanf("%u",&p->etud.age);
printf("\nAdresse: ");
printf("\nRue: ");
fflush(stdin);
gets(p->etud.adr.rue);
printf("\nVille; ");
fflush(stdin);
gets(p->etud.adr.ville);
printf("\nCode postal: ");
scanf("%u",&p->etud.adr.cod_pos);
do
{
printf("\nNote de la matiere 1: ");
scanf("%d",&p->etud.note1);
if (p->etud.note1<0 || p->etud.note1>20) printf("\nLa nte doit etre comprise entre 0 et 20.Entrer de nouveau la note de la matière 1");
}while(p->etud.note1<0 || p->etud.note1>20);
do
{
printf("\nNote de la matiere 2: ");
scanf("%d",&p->etud.note2);
if (p->etud.note2<0 || p->etud.note2>20) printf("\nLa nte doit etre comprise entre 0 et 20.Entrer de nouveau la note de la matière 2");
}while(p->etud.note2<0 || p->etud.note2>20);
do
{
printf("\nNote de la matiere 3: ");
scanf("%d",&p->etud.note3);
if (p->etud.note3<0 || p->etud.note3>20) printf("\nLa nte doit etre comprise entre 0 et 20.Entrer de nouveau la note de la matière 3");
}while(p->etud.note3<0 || p->etud.note3>20);
p->etud.moy=(p->etud.note1*coef1 + p->etud.note2*coef2 + p->etud.note3*coef3)/(coef1+coef2+coef3);
p->etud.rang=0;
p->lien=*l;
*l=p;
printf("%f",(*l)->etud.moy);
getch();
}
}