Bien programmer en langage C
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le Deal du moment : -17%
Casque de réalité virtuelle Meta Quest 2 ...
Voir le deal
249.99 €

Aide programme plante, où?

2 participants

Aller en bas

Aide programme plante, où? Empty Aide programme plante, où?

Message  pascal Ven 1 Avr 2011 - 20:35

Bonjour,

J'ai écris un programme qui permet de créer une liste chainée simple, de remplir un élement de cette liste par les lignes d'un fichier donnée et de l'afficher. Cependant, ça ne marche pas. Il plante. Quelqu'un pourrait-il m'aider à identifier l'erreur et la corriger?
Merci par avance de votre aide.
Code:
#include<stdio.h>
#include<stdlib.h>


typedef struct noeud noeud;
struct noeud{
  int identifiant;
  double abscisse;
  double ordonee;
  int demande;                    /*demande du client*/
  int temps_service;
  int borne_inf_tw;
  int borne_sup_tw;
  int capacite;
  struct noeud *suivant;

};
typedef noeud* llist;

llist ajouter_noeud(llist liste, int id, double abs, double ord, int dde, int tps_service, int b_inf_tw, int b_sup_tw, int cap)
{
  noeud* nouveau = malloc(sizeof(noeud));
  nouveau->identifiant = id;
  nouveau->abscisse = abs;
  nouveau->ordonee = ord;
  nouveau->demande = dde;
  nouveau->temps_service = tps_service;
  nouveau->borne_inf_tw = b_inf_tw;
  nouveau->borne_sup_tw = b_sup_tw;
  nouveau->capacite = cap;
  nouveau->suivant = NULL;

  return nouveau;
}
void afficher_liste(llist liste)
{
  noeud *p = liste;
  printf("contenu de la liste\n");
  while(p!= NULL)
  {
      printf("%d %lf %lf %d %d %d %d %d\n", p->identifiant,p->abscisse, p->ordonee, p->demande, p->temps_service, p->borne_inf_tw, p->borne_sup_tw, p->capacite);
      p = p->suivant;
  }
}
int main (void)
{
  llist ma_liste = NULL;
  int id;
  double abs;
  double ord;
  int dde;
  int tps_service;
  int b_inf_tw;
  int b_sup_tw;
  int cap;
  FILE *fp;

  if(ma_liste!= NULL)
      printf("la liste est non vide \n");
  fp = fopen("D:\\Codes Thèse\\TS2004t3\\test.txt", "r");
   if(fp == NULL)
   {
      printf("Impossible d'ouvrir fichier donnees .txt \n");
      exit (-1);
   }

   while (fscanf(fp,"%d %lf %lf %d %d %d %d", id, abs, ord, dde, tps_service, b_inf_tw, b_sup_tw, cap)== 7)
      ajouter_noeud(ma_liste, id , abs, ord, dde, tps_service, b_inf_tw,  b_sup_tw, cap);


  afficher_liste(ma_liste);
  fclose (fp);

  getchar();
   return EXIT_SUCCESS;

}

Fichier donnée:
0 12,23 -12,33 +3 1 1 5 4
1 10, 11 22, 10 -1 1 1 7 4
2 22, 34 12,34 -2 1 1 9 4
3 42,33 23,24 +4 1 1 10 4
4 15,66 17,89 -2 1 1 14 4
5 22, 13 42,35 -2 1 1 20 4

pascal
Bavard
Bavard

Messages : 20
Date d'inscription : 20/08/2009

Revenir en haut Aller en bas

Aide programme plante, où? Empty Re: Aide programme plante, où?

Message  -ed- Mer 13 Avr 2011 - 15:57

La correction de ces avertissements devraient mettre de l'ordre :
Code:


-------------- Build: Debug in 01 ---------------

Compiling: main.c
C:\dev\bien-prog\pascal\01\main.c: In function 'main':
C:\dev\bien-prog\pascal\01\main.c:67:4: warning: format '%d' expects type 'int *', but argument 3 has type 'int'
C:\dev\bien-prog\pascal\01\main.c:67:4: warning: format '%lf' expects type 'double *', but argument 4 has type 'double'
C:\dev\bien-prog\pascal\01\main.c:67:4: warning: format '%lf' expects type 'double *', but argument 5 has type 'double'
C:\dev\bien-prog\pascal\01\main.c:67:4: warning: format '%d' expects type 'int *', but argument 6 has type 'int'
C:\dev\bien-prog\pascal\01\main.c:67:4: warning: format '%d' expects type 'int *', but argument 7 has type 'int'
C:\dev\bien-prog\pascal\01\main.c:67:4: warning: format '%d' expects type 'int *', but argument 8 has type 'int'
C:\dev\bien-prog\pascal\01\main.c:67:4: warning: format '%d' expects type 'int *', but argument 9 has type 'int'
C:\dev\bien-prog\pascal\01\main.c:67:4: warning: too many arguments for format
C:\dev\bien-prog\pascal\01\main.c:68:20: warning: 'id' may be used uninitialized in this function
C:\dev\bien-prog\pascal\01\main.c:68:20: warning: 'abs' may be used uninitialized in this function
C:\dev\bien-prog\pascal\01\main.c:68:20: warning: 'ord' may be used uninitialized in this function
C:\dev\bien-prog\pascal\01\main.c:68:20: warning: 'dde' may be used uninitialized in this function
C:\dev\bien-prog\pascal\01\main.c:68:20: warning: 'tps_service' may be used uninitialized in this function
C:\dev\bien-prog\pascal\01\main.c:68:20: warning: 'b_inf_tw' may be used uninitialized in this function
C:\dev\bien-prog\pascal\01\main.c:68:20: warning: 'b_sup_tw' may be used uninitialized in this function
C:\dev\bien-prog\pascal\01\main.c:68:20: warning: 'cap' may be used uninitialized in this function
Linking console executable: bin\Debug\01.exe
Output size is 30,78 KB
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 16 warnings
-ed-
-ed-
Admin
Admin

Messages : 290
Date d'inscription : 26/05/2008
Age : 67
Localisation : Paris 14eme arrondissement (75, France)

http://bien-programmer.fr

Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum
Ne ratez plus aucun deal !
Abonnez-vous pour recevoir par notification une sélection des meilleurs deals chaque jour.
IgnorerAutoriser