Skip to content
Snippets Groups Projects
Commit 53f64f78 authored by vautrin33u's avatar vautrin33u
Browse files

Erreur désallocation mémoire et lecture fichier corrigé

parent 07068bb0
Branches
No related tags found
No related merge requests found
...@@ -65,31 +65,31 @@ char** lire_fichier (const char* nomFichier){ //malfonctionne ...@@ -65,31 +65,31 @@ char** lire_fichier (const char* nomFichier){ //malfonctionne
printf("Erreur: fichier inaccessible \n"); printf("Erreur: fichier inaccessible \n");
fclose(fichier); fclose(fichier);
return NULL; return NULL;
}else{ }
//Création du tableau réceptacle //Création du tableau réceptacle
int ligne = 0; int ligne = 0;
int colonne = 0; int colonne = 0;
taille_fichier(nomFichier, &ligne, &colonne); taille_fichier(nomFichier, &ligne, &colonne);
//printf("\n Taille ligne: %d | colonne : %d \n", ligne, colonne); //printf("\n Taille ligne: %d | colonne : %d \n", ligne, colonne);
char** tab = allouer_tab_2D(colonne, ligne);//inversion ligne char** tab = allouer_tab_2D(ligne, colonne);
for (int i=0; i<ligne; i++){ for (int i=0; i<ligne; i++){
for (int j=0; j<colonne; j++){ for (int j=0; j<colonne; j++){
tab[i][j] = '\0'; 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){ void genere_fichier (const char* nomFichier, char** source, int ligne, int colonne){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment