Bonjour,

Comme le titre l'indique j'ai quelques problèmes et je ne comprend pas trop d'où ils viennent, donc plutôt que d'essayer d'expliquer je vais tout vous mettre.

fichier.c
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
#include <stdio.h>
#include <stdlib.h>
 
#include "fichier.h"
#include "graphe.h"
 
void ouvertureFichier (void) {
    char entree [50];
    FILE* fichier=NULL;
    int nbrSommets;
 
    printf ("Quelle fichier voulez-vous ouvrir ?\n");
 
    gets (entree);//Permet de vider le tampon qui contient le \n de la dernière saisie
    gets (entree);
    char *nomFichier=entree;
    fichier=fopen(nomFichier, "a+");
 
    if (fichier!=NULL) {
        printf ("L'ouverture du fichier a été un succés.\n");
        struct table* graphe=malloc(sizeof(struct table));
        graphe->poid=-1;
        graphe=lectureFichier (fichier, graphe);
 
        printf ("Le fichier a été lu correctement.\n");
        actionsGraphe (graphe);
        close(fichier);
    }
    else {
        printf ("Il y a eut un problème lors de l'ouverture du fichier.\n");
    }
}
 
struct table* lectureFichier (FILE* fichier, struct table* graphe) {
    int nbrSommets, nbrAretes, sommet1, sommet2, poid, i;
 
    fscanf (fichier, "%d", &nbrSommets);
    fseek(fichier, 1, SEEK_CUR);//permet de passer à la ligne 2 pour lire le nombre correspondant au nombre d'arcs
    fscanf (fichier, "%d", &nbrAretes);
    for (i=0 ; i<nbrAretes ; i++) {
 
        fseek(fichier, 1, SEEK_CUR); //permet de passer à la ligne suivante
        fscanf (fichier, "%d %d %d", &sommet1, &sommet2, &poid); //permet de lire la ligne, et de récupperrer son contenue
 
        graphe=insererArete (graphe, sommet1, sommet2, poid);
    }
 
    graphe->nbrSommets=nbrSommets;
    graphe->nbrAretes=nbrAretes;
 
    return graphe;
}
 
void ecritureFichier (struct table* graphe) {
    int nbrSommets, nbrAretes;
    char tampon, *nomFichier;
    char entree [50];
    FILE* fichier;
    nbrSommets=graphe->nbrSommets;
    nbrAretes=graphe->nbrAretes;
 
 
    printf ("Quel est le nom que vous voulez donner au fichier ?\n");
    gets (entree);//Permet de vider le tampon qui contient le \n de la dernière saisie
    gets (entree);
    nomFichier=entree;
 
    fichier=fopen (nomFichier, "w+");
 
    if (fichier!=NULL) {
        fprintf (fichier, "%d", nbrSommets); //permet d'écrire le nombre de sommets du graphe
        fprintf (fichier, "\n%d", nbrAretes); //permet d'écrire le nombre d'arcs du graphe
 
        ecrireGraphe (fichier, graphe);
        printf ("Le graphe a bien été écrit dans le fichier %s.\n", nomFichier);
 
        close(fichier);
    }
}
 
void ecrireGraphe (FILE* fichier, struct table* graphe) {
 
    ecrireAretes (fichier, graphe->listeAretes, graphe->poid);
 
    if (graphe->listeSuivante!=NULL) {
        ecrireGraphe (fichier, graphe->listeSuivante);
    }
 
}
 
void ecrireAretes (FILE* fichier, struct arete* aretes, int poid) {
 
    fprintf (fichier, "\n%d %d %d", aretes->sommetDepart, aretes->sommetArrive, poid);
 
    if (aretes->areteSuivante!=NULL) {
        ecrireAretes (fichier, aretes->areteSuivante, poid);
    }
}
fichier.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
#include <stdlib.h>
#include <stdio.h>
 
void ouvertureFichier (void);
struct table* lectureFichier (FILE* fichier, struct table* graphe);
void ecritureFichier (struct table* graphe);
void ecrireGraphe (FILE* fichier, struct table* graphe);
void ecrireAretes (FILE* fichier, struct arete* aretes, int poid);
graphe.h
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
#include <stdlib.h>
#include <stdio.h>
 
struct arete {
    int sommetDepart;
    int sommetArrive;
    struct arete* areteSuivante;
};
 
struct table {
    int nbrSommets;
    int nbrAretes;
    int poid;
    struct table* listeSuivante;
    struct arete* listeAretes;
};
Les erreurs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
In file included from fichier.c:4:
fichier.h:10: warning: ‘struct arete’ declared inside parameter list
fichier.h:10: warning: its scope is only this definition or declaration, which is probably not what you want
fichier.c: In function ‘ecrireGraphe’:
fichier.c:83: warning: passing argument 2 of ‘ecrireAretes’ from incompatible pointer type
fichier.h:10: note: expected ‘struct arete *’ but argument is of type ‘struct arete *’
fichier.c: At top level:
fichier.c:91: error: conflicting types for ‘ecrireAretes’
fichier.h:10: note: previous declaration of ‘ecrireAretes’ was here
Si dans le fichier.h je met un #include "graphe.h" ça me mets encore plus d'erreurs !


S'il vous plait, pouvez-vous m'aider ?

Merci d'avance.


PS : j'aime bien la note de la ligne 6 ! :p