Liste chaine simple je di mal a compiler quelqu un peut m'aider

Farhan -  
Dalfab Messages postés 706 Date d'inscription   Statut Membre Dernière intervention   -
#include <stdio.h>
#include <stdlib.h>
#include<string.h>

struct date{
 int j;
 int m;
 int a;
};
struct employer{
 int mat ;
 char nom[10];
 char prenom[10];
 char adress[15];
 struct date DE;
 int telephone;
 char service;
 float salairebrut;
 struct employer *suiv;
};
typedef struct employer *liste;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
liste creation(liste l){
 liste tete,p;
 int n;
 tete=malloc(sizeof(liste));
 printf("mat:\n");
 scanf("%d",&tete->mat);
 printf("nom:\n");
 scanf("%s",&tete->nom);
 printf("prenom:\n");
 scanf("%s",&tete->prenom);
 printf("adresse:\n");
 scanf("%s",&tete->adress);
 printf("\n==========date d'enbauchemant==========\n");
 printf("jour:\n");
 scanf("%d",&tete->DE.j);
 printf("mois:\n");
 scanf("%d",&tete->DE.m);
 printf("anneé:\n");
 scanf("%d",&tete->DE.a);
 printf("telephone:\n");
 scanf("%d",&tete->telephone);
 printf("service ou ils/elles appatient:\n");
 scanf("%c",&tete->service);
 printf("salairebrute:\n");
 scanf("%f",&tete->salairebrut);
 tete->suiv=NULL;
 l=tete;
 do{
  p=malloc(sizeof(liste));
  printf("mat:\n");
  scanf("%d",&p->mat);
  if(p->mat==tete->mat){
   printf("\nDesole le matricule existe deja veuillez le resaisire\n");break;
  }
  else{
   
   printf("nom:\n");
   scanf("%s",&p->nom);
   printf("prenom:\n");
   scanf("%s",&p->prenom);
   printf("adresse:\n");
   scanf("%s",&p->adress);
   printf("\n==========date d'enbauchemant==========\n");
   printf("jour:\n");
   scanf("%d",&p->DE.j);
   printf("mois:\n");
   scanf("%d",&p->DE.m);
   printf("anneé:\n");
   scanf("%d",&p->DE.a); 
   printf("telephone:\n");
   scanf("%d",&p->telephone);
   printf("service ou ils/elles appatient:\n");
   scanf("%c",&p->service);
   printf("salairebrute:\n");
   scanf("%f",&p->salairebrut);
   
  }
   p->suiv=NULL;
   l->suiv=p;
   l=p;
  printf("\nvoulez vous ajoute une autre employer\n");
  scanf("%d",&n);
 }while(n!= 0);
  l=tete;
return l;
}
void affiche(liste l){
 printf("\n===================Voici votre liste complete des employer====================\n");
 while(l != NULL){ 
  printf("%d-->",l->mat);
  printf("%s-->",l->nom);
  printf("%s-->",l->prenom);
  printf("%s-->",l->adress);
  printf("%d-->",l->DE.j);
  printf("%d-->",l->DE.m);
  printf("%d-->",l->DE.a);
  printf("%d-->",l->telephone);
  printf("%c-->",l->service);
  printf("%f-->",l->salairebrut);
  l=l->suiv;
  printf("\n");
 }
}


EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici : ICI

Merci d'y penser dans tes prochains messages.
A voir également:

2 réponses

NHenry Messages postés 15219 Date d'inscription   Statut Modérateur Dernière intervention   365
 
Quel message d'erreur ou quel comportement incorrect ?
0
Dalfab Messages postés 706 Date d'inscription   Statut Membre Dernière intervention   101
 
Bonjour,

Il nous faut plus d'infos. Ce que j'ai vu c'est que tes allocations sont beacoup trop petites. Ligne 26 et 51, tu ne réserves que
sizeof(list)
qui est un pointeur, il faut réserver l'enregistrement qui sera pointé, par exemple:
tete = malloc(sizeof(liste*));
tete = malloc(sizeof(struct enregistrement)); // ou plus compréhensible
tete = malloc( sizeof(*tete) ); // ou le plus simple (pas besoin de chercher l'info ailleurs)
0