Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int** setMatrice(){
- int **M;
- int nbl,nbc;
- FILE *fi= fopen("matriceCo.txt","r+");
- if(fi){
- fscanf(fi,"%d %d",&nbc,&nbl);
- M=malloc(nbl*sizeof(int*));
- for(int i=0;i<nbl;i++)
- M[i]=malloc(nbc*sizeof(int));
- for(int i=0; i<nbl; i++){
- for(int j=0; j<nbc; j++)
- fscanf(fi,"%d",&M[i][j]);
- }
- fclose(fi);
- }
- return M;
- }
- //===================================================================
- int* setMot(FILE* f , int *taille)
- {
- char* mot=malloc(20*sizeof(char));
- int* tab;
- if(f){
- fscanf(f,"%s ",mot);
- tab=malloc(strlen(mot)*sizeof(int));
- for(int i=0; i<strlen(mot); i++)
- {
- if(mot[i]=='+')
- tab[i]=10;
- else if(mot[i]=='-')
- tab[i]=11;
- else if(mot[i]=='i')
- tab[i]=12;
- else
- tab[i]=mot[i]-'0';
- }
- *taille=strlen(mot);
- }
- return tab;
- }
- //==================================================================================
- int trace(int** M, int* mot, int taille_mot, int ETAT_INIT){
- int suivant=ETAT_INIT;
- for(int i=0 ; i<taille_mot && suivant!=-1 ; i++){
- suivant=M[suivant][mot[i]];
- }
- return suivant;
- }
- //==================================================================================
- void reconaissance(int R)
- {
- if(R==5)
- printf(" ==> mot existe ");
- else
- printf(" ==> mot n'existe pas ");
- }
- //========================================================================
- int main(){
- int **M;
- FILE* fi;
- int* mot;
- int ETAT_INIT,taille;
- M=setMatrice();
- printf("Entrer l'etat initial :");scanf("%d",&ETAT_INIT);
- fi=fopen("motComplexeE.txt","r+");
- system("cls");
- while(!feof(fi))
- {
- mot=setMot(fi,&taille);
- for(int i=0 ;i<taille ; i++)
- {
- if(mot[i]==10)
- printf("+");
- else if(mot[i]==11)
- printf("-");
- else if(mot[i]==12)
- printf("i");
- else
- printf("%c",mot[i]+'0');
- }
- reconaissance(trace(M,mot,taille,ETAT_INIT));
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement