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 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <windows.h>
void simulation(char car, char car2 ,struct Automate);
struct transition
{
char entree [10];
char etat_suivant;
char sortie [200];
};
struct transition_etat
{
char nom_etat[10];
int nb_entree_utilisees;
struct transition TR[10];
};
struct Automate
{
int nb_etats;
struct transition_etat E[35];
};
int main(int argc, char* argv[])
{
char E="";
char car ,car2, *b;
int a, i=0,j=6;
struct Automate autom ;
FILE*f;
f = fopen("petit train.txt","r");
// affichage du fichier à l'ecran
if (f!=NULL)
{
//getchar();
/* while(car!='z')
{
fscanf(f,"%c",&car);
printf("%c",car);
}*/
do // lecture du fichier afin de trouver la valeur du nombre d'état
{
fscanf(f,"%c",&car);
printf("%c",car);
}while(car!=':');
fscanf(f,"%d",&autom.nb_etats);
printf("%d\n",autom.nb_etats);
fscanf(f,"%c",&car);
for (i=0; i<4 ; i++)
{
while(car!=':')
{
fscanf(f,"%c",&car);
//printf("%c",car);
// lecture du fichier en ne prenant pas en compte les 5 premières lignes
}
fscanf(f,"%c",&car);
}
j=0;
do
{
i=0;
do
{
fscanf(f,"%c",b) ; // saisie des Etats
//printf("%c",*b);
autom.E[j].nom_etat[i]=*b;
i++;
} while(*b!=' ');
autom.E[j].nom_etat[i]='\0';
printf("%s", autom.E[j].nom_etat);
do
{
fscanf(f,"%c",&car);
//printf("%c",car);
}while(car!='\n');
j++;
}while(j!=33);
printf("\n\nvous etes dans la fonction simulation");
/*
for (i=0 ; i<38; i++)
{
while(car!='\n')
{
fscanf(f,"%c",&car);
printf("%c",car);
} // on va la lecture jusqu'à la ligne 38 ou se situe les transitions types
fscanf(f,"%c",&car);
}
fclose(f);
}
else
{
printf("Probleme avec l'ouverture du fichier");
}
*/
//printf("saisir une instruction");
printf("\nsaisir instruction\n"); // saisie de l'instruction
scanf("%c",&E);
do
{
fscanf(f,"%c",&car);
printf("%c",car);
}while(car!='\n');
b=&car;
int k= 0;
while(car!='*')
{
fscanf("%c", b);
//printf("%c",*b);
autom.E[1].TR[1].entree[k]=*b;
k++;
// recherche de la sortie associée
}
autom.E[1].TR[1].entree[k]='\0';
fscanf(f,"%c",&car);
fscanf(f,"%c",&car);
if (car==E)
{
j=0;
do
{
i=0;
scanf("%c",b);
printf("%c", *b);
autom.E[j].TR[i].etat_suivant=*b;
i++;
} while(car!='\n');
}
else
{
do
{
scanf("%c",&car);
} while(car=='transition','entree'); // affichage du message mauvaise instruction
printf("mauvaise instruction");
}
do
{
scanf("%c",&car);
}while(car!='transition','entree');
do
{
scanf("%c",&car); // affichage de la sortie associée
printf("%c", car);
autom.E[i].TR[i].sortie[i]+=car;
}while(car!='\n');
printf("%c", car);
fclose(f);
//char simulation(car2, transition.entree);
}
} |
Partager