From 53f64f78ce087234a07b5482007f2fdd294215b7 Mon Sep 17 00:00:00 2001 From: vautrin33u <vautrin33u@etu.univ-lorraine.fr> Date: Wed, 18 Nov 2020 11:01:47 +0100 Subject: [PATCH] =?UTF-8?q?Erreur=20d=C3=A9sallocation=20m=C3=A9moire=20et?= =?UTF-8?q?=20lecture=20fichier=20corrig=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion_fichiers.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/gestion_fichiers.c b/gestion_fichiers.c index 5e6b567..fedb794 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){ -- GitLab