Bonsoir !
Je dois ajouter des noeuds dans une liste chaînée depuis un fichier et ça ne marche pas . la fonction d'affichage affiche des adresses bizarres... voici le code de la fonction qui charge depuis le fichier et de la fonction d'affichage .
Merci pour votre aide !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
      	FILE *fichier;
	char nomV[20],designation[20];
	int prix, nbplaces;
	fichier=fopen(FICHIER,"r");
 
while(fscanf(fichier,"%s,%s,%d,%d \n\n ",nomV, designation, prix, nbplaces) != EOF)
	{
     ajouterprestation(nomV, designation, prix, nbplaces); 
 
     }                                                 
 
    fclose(fichier);

Fonction d'affichage :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
void afficherlesprestationsparville(char * nomV)
        {
printf("\n \n designation, prix, nombre de places restantes :\n \n ");
int i;
prestation *p;
for(i=0;i<n;i++)
if(strcmp(T[i].nomVille,nomV)==0)
break;
if(i<n)
{
p=T[i].listeprestations;
while(p!=NULL)
{
printf("\n %s,%d,%d\n",p->designation, p->prix, p->nbplaces);
p=p->psuivante;
}
}
else 
printf("La ville n'existe pas\n");
        }
La fonction d'ajout marche bien apparemment mais je l'écris quand meme :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
/*----------------------------*/
#define TAILLE 30
#define FICHIER "text.txt"
/*----------------------------*/
typedef struct date
{
  int mois;
  int jour;
  int annee;
}date;
 
typedef struct prestation
{
  char * ville;
  char * designation;
  date datedebut ;
  date datefin ;
  int prix;
  int nbplaces ;
  struct prestation * psuivante;
}prestation;
 
typedef struct ville 
{
  char nomVille[25];
  prestation * listeprestations;
}ville; 
/*----------------------------*/
date SaisieDate(char * mes)
{
  date pp;
  if(mes != NULL) printf(mes);
  do
  {
     printf(" \tJour:(jj)\t");
     scanf("%d",&pp.jour);
  }while(pp.jour<=0||pp.jour>31);
  do
  {
     printf(" \tMois:(mm)\t");
     scanf("%d",&pp.mois);
  }while(pp.mois<=0||pp.mois>12);
  do
  {
     printf(" \tAnnee:(aaaa)\t");
     scanf("%d",&pp.annee);
  }while(pp.annee<=1930||pp.annee>2010);
  return pp;
}
/*----------------------------*/
ville T[TAILLE];
int n=0;
/*----------------------------*/
int ajouterprestation(char * nomV, char * designation, int prix, int nbplaces)
{
//  int n=0;  ??????????????????????????????????
  int b ;
  int i;
  FILE *f;
  prestation *Npres=(prestation*) malloc(sizeof(prestation));
  if(Npres==NULL) return 0;
 Npres->designation = strdup(designation);
 
 
  designation = (char *) malloc(300 * sizeof(char));
  Npres->ville=nomV;
  Npres->prix=prix;
  Npres->nbplaces=nbplaces;
  Npres->datedebut=SaisieDate(" \tDonner la date de debut de la prestation :\n");
  Npres->datefin=SaisieDate(" \tDonner la date de fin de la prestation :\n");
  Npres->psuivante=NULL;
  for(i=0;i<n;i++)
  {
     if(!strcmp(T[i].nomVille,nomV)) break;}
     if(i<n) //ville existe déjà
     {
         prestation *p=T[i].listeprestations;
         while(p->psuivante!=NULL)
         {
            p=p->psuivante;
         }
         p->psuivante=Npres;
        /* f=fopen(FICHIER,"a");
         fprintf(f,"%s,%s,%d,%d",Npres->ville, Npres->designation, Npres->prix, Npres->nbplaces);
         fclose(f);
        return 1;*/
     }
     else //ville n'existe pas
     {
        printf("h");
        if(n==TAILLE) //il n y a plus d'espace pour inserer une nouvelle ville
        {
           free(Npres);
           return 0;
        }
        strcpy(T[i].nomVille,nomV);
        T[i].listeprestations=Npres;
        n++;
       /* FILE *f;
        f=fopen(FICHIER,"a");
        fprintf(f,"%s,%s,%d,%d \n\n ",Npres->ville, Npres->designation, Npres->prix, Npres->nbplaces);
        fclose(f);
        return 1;*/
     }
  }
Merci pour votre aide !
a+