#include #include #include #include #include #define TAILLE_BUF 30 #define NO_Depots "NO_Staff" #define NO_Clients "NO_Visits" #define TOKEN_PARAM "param" #define TOKEN_SET "set" FILE *ficl; char mot[TAILLE_BUF]; char c; //Mes structures à remplir: int Nb_Clients, Nb_Depots; int Nb_Noeuds; //Mes structures: //pour les sommets: typedef struct Noeuds{ int ID; int D; int a_i,b_i; //int Type; }Noeuds; Noeuds *ListeClients; //les tableaux utilisés (à remplir!) float DFactor=1.0; //Fonction qui lit un caractère: char read_c(void) { char a; a=fgetc(ficl); return a; } //Fonction qui permet de lire un mot: void read_mot(void) { int i=0; // printf("Entree rm >%c<\n",c); while ((c=='#')||(c==' ') || (c=='\n') || (c==';')) { if (c=='#') { // Commentaire on passe while ((c !='\n') && (c!=EOF)) c=read_c(); } if (c==' ') { // les blancs while ((c=read_c()) ==' '); } if (c=='\n') { // les blancs while ((c=read_c()) =='\n'); } if (c==';') { // les ; while ((c=read_c()) ==';'); } } if ((isalpha(c))||(c=='_')) while ((isalpha(c))||(c=='_')) { mot[i++]=c; c=read_c();} else { if (c=='-') {mot[i++]=c; c=read_c();} if (isdigit(c)|| (c=='.')) while ((isdigit(c))||(c=='.')) {mot[i++]=c; c=read_c();} else { if (c==':' ) { mot[i++]=c; c=read_c(); if (c=='=') {mot[i++]=c; c=read_c();} } else { mot[i++]=c; c=read_c(); } } } mot[i]='\0'; } //Fonction pour remplir les deux premières valeurs (nombre de clients et de dépôts, ainsi la totalité "noeuds"), //pour les deux premières lignes, //et création d'un Noeud, void charge_param(char *m) { //printf("charge_param \n"); if (!strcmp(mot,NO_Depots)) { read_mot(); read_mot(); Nb_Depots=atoi(mot); read_mot(); } else { if (!strcmp(mot,NO_Clients)) { read_mot(); read_mot(); Nb_Clients=atoi(mot); Nb_Noeuds=Nb_Depots+Nb_Clients; ListeClients=(Noeuds*)malloc((Nb_Clients+1)*sizeof(Noeuds)); read_mot(); } else { // Parametre qui ne sert pas.... read_mot(); read_mot(); read_mot(); } } } void charge_windows(void) { int indice,a,b; //printf("charge_windows \n"); read_mot(); // : read_mot(); // a read_mot(); // b read_mot(); // := do { indice=atoi(mot); // On a l'indice read_mot(); a=atoi(mot); // On a a read_mot(); b=atoi(mot); // On a b read_mot(); ListeClients[indice].a_i=a; ListeClients[indice].b_i=b; } while(indice < Nb_Clients + 1); } void charge_duration(void) { int indice,a; printf("charge_duration \n"); read_mot(); // Duration read_mot(); // [ read_mot(); // * read_mot(); // ] read_mot(); // := //read_mot(); do { indice=atoi(mot); // On a l'indice read_mot(); a=atoi(mot); // On a a read_mot(); ListeClients[indice].D=a*DFactor; } while(strcmp(mot,TOKEN_PARAM)); } int main() { int i; // ouverture du fichier ficl = fopen("essai.txt", "r"); // ouvrir en lecture if(ficl == NULL){ printf("Impossible d'ouvrir le fichier \n"); exit(1); } c=read_c(); read_mot(); while (!strcmp(mot,TOKEN_PARAM)) {read_mot(); charge_param(mot);} printf("Nombre de dépôts est %d\n",Nb_Depots); printf("Nombre de Clients est %d\n",Nb_Clients); printf("ok param \n"); if (!strcmp(mot,TOKEN_PARAM)) {read_mot(); charge_windows();} printf("ok windows\n"); if (!strcmp(mot,TOKEN_PARAM)) {read_mot(); charge_duration();} printf(".... %d\n",ListeClients[4].D); printf("ok duration\n"); return 0; }