diff --git a/gestion_fichiers.c b/gestion_fichiers.c index 5e6b56794ae450a61bd471b2cbbe9b249856cc00..fedb794f2ff2ef01ad2e4045818b72e181196eff 100644 --- a/gestion_fichiers.c +++ b/gestion_fichiers.c @@ -65,31 +65,31 @@ char** lire_fichier (const char* nomFichier){ //malfonctionne printf("Erreur: fichier inaccessible \n"); fclose(fichier); return NULL; - }else{ - //Création du tableau réceptacle - int ligne = 0; - int colonne = 0; - taille_fichier(nomFichier, &ligne, &colonne); - //printf("\n Taille ligne: %d | colonne : %d \n", ligne, colonne); - char** tab = allouer_tab_2D(colonne, ligne);//inversion ligne - - for (int i=0; i<ligne; i++){ - for (int j=0; j<colonne; j++){ - tab[i][j] = '\0'; - } + } + //Création du tableau réceptacle + int ligne = 0; + int colonne = 0; + taille_fichier(nomFichier, &ligne, &colonne); + //printf("\n Taille ligne: %d | colonne : %d \n", ligne, colonne); + char** tab = allouer_tab_2D(ligne, colonne); + + for (int i=0; i<ligne; i++){ + for (int j=0; j<colonne; j++){ + tab[i][j] = '\0'; } - //Parcours du fichier - char c = '\0'; //fgetc(fichier); - for (int i=0; c!=EOF && i<=ligne; i++){ - for (int j=0; c!=EOF && j<=colonne; j++){ - c = fgetc(fichier); - if (c=='\n') break; - tab[i][j] = c; - } - } - fclose(fichier); - return tab; } + //Parcours du fichier + char c = '\0'; //fgetc(fichier); + for (int i=0; i<=ligne; i++){ + for (int j=0; j<=colonne; j++){ + c = fgetc(fichier); + if (c=='\n' || c== EOF) break; + tab[i][j] = c; + } + } + fclose(fichier); + return tab; + } void genere_fichier (const char* nomFichier, char** source, int ligne, int colonne){