| 12
 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
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 
 |  
#include <stdlib.h>
#include <stdio.h>
 
 
typedef struct Chainon Chainon;
struct Chainon
{
 	int indiceSommet;
 	Chainon *suivant;
 	int nombreJetons;
	char type;
};
 
 
 
typedef struct Reseau Reseau;
struct Reseau
{
	int *Place;
	int nombrePlace;
 
	int *Transition;
	int nombreTransition;
 
	Chainon* *Arcs;
	int nombreArcs;
};
 
 
int main(void)
{
    Reseau Pietri;
 
    /* Initialisation de la structure Pietri */
	Pietri.Place = NULL;
	Pietri.nombrePlace = 0;
	Pietri.Transition = NULL;
	Pietri.nombreTransition = 0;
	Pietri.Arcs = NULL;
	Pietri.nombreArcs = 0;
 
 
 
	FILE* fichier = fopen("reseau.txt","r");
	if (fichier == NULL)
	{
        perror("Erreur lors du chargement du fichier \"reseau.txt\" ");
        return EXIT_FAILURE;
    }
 
 
	/********************************* PLACES *********************************/
    int nombre;
    while (fscanf(fichier, "%d ", &nombre) == 1)
    {
        int *Temporaire = (int*) realloc (Pietri.Place, sizeof(int)*(Pietri.nombrePlace+1));
        if (Temporaire == NULL)
        {
            perror ("realloc a echoue lors de la lecture de la ligne \"Place\" ");
            /* Faire une action, a toi de voir (Quitter, continuer ?) */
        }
        else
        {
            /* On recupere l'ancien tableau avec une case en plus */
            Pietri.Place = Temporaire;
            /* On insere la nouvelle valeur */
            Pietri.Place[Pietri.nombrePlace] = nombre;
            /* et on n'oublie pas ... ^^ */
            Pietri.nombrePlace++;
        }
 
    }
 
 
 
	/****************************** TRANSITIONS *******************************/
	/* On s'est arreter a '*' avant, on va donc avancer d'un caractere */
	fseek(fichier,1,SEEK_CUR);
    while (fscanf(fichier, "%d ", &nombre) == 1)
    {
        int *Temporaire = (int*) realloc (Pietri.Transition, sizeof(int)*(Pietri.nombreTransition+1));
        if (Temporaire == NULL)
        {
            perror ("realloc a echoue lors de la lecture de la ligne \"Place\" ");
            /* Faire une action, a toi de voir (Quitter, continuer ?) */
        }
        else
        {
            Pietri.Transition = Temporaire;
            Pietri.Transition[Pietri.nombreTransition] = nombre;
            Pietri.nombreTransition++;
        }
 
    }
 
 
    /********************************** ARCS* *********************************/
	fseek(fichier,1,SEEK_CUR);
    while (fscanf(fichier, "%d:", &nombre) == 1)
    {
        Chainon **Temp = (Chainon**) realloc (Pietri.Arcs, sizeof(Chainon*)*(Pietri.nombreArcs+1));
        if (Temp == NULL)
        {
            perror ("realloc a echoue lors de la lecture de la ligne \"Place\" ");
            /* Faire une action, a toi de voir (Quitter, continuer ?) */
        }
        else
        {
            Pietri.Arcs = Temp;
            Pietri.Arcs[Pietri.nombreArcs] = NULL;
 
 
            /* On insere tout les arcs chaines */
            int numeroArc;
            if (fscanf(fichier, "%d ", &numeroArc) == 1)
            {
                Pietri.Arcs[Pietri.nombreArcs] = (Chainon*) malloc (sizeof(Chainon));
 
                Pietri.Arcs[Pietri.nombreArcs]->indiceSommet = numeroArc;
                //Pietri.Arcs[Pietri.nombreArcs]->nombreJetons
                Pietri.Arcs[Pietri.nombreArcs]->suivant = NULL;
                //Pietri.Arcs[Pietri.nombreArcs]->type
 
                Chainon* pointeur = Pietri.Arcs[Pietri.nombreArcs];
 
                while (fscanf(fichier, "%d ", &numeroArc) == 1)
                {
                    Chainon *nouveau = (Chainon*) malloc (sizeof(Chainon));
                    nouveau->indiceSommet = numeroArc;
                    //nouveau->nombreJetons
                    nouveau->suivant = NULL;
                    //nouveau->type
 
                    pointeur->suivant = nouveau;
                    pointeur = nouveau;
                }
 
            }
 
            Pietri.nombreArcs++;
            fseek(fichier,1,SEEK_CUR);
        }
    }
 
 
    int i;
    for (i=0 ; i<Pietri.nombreArcs ; i++)
    {
        printf("%d:", i);
        Chainon* parcours;
        for (parcours=Pietri.Arcs[i] ; parcours!=NULL ; parcours=parcours->suivant)
            printf("%d ", parcours->indiceSommet);
        printf("\n");
    }
 
 
 
 
    return EXIT_SUCCESS;
} |