Hello i would like to store a matrix into a file here's the code I made
void fichier_print(grid_t grille, int n){
int i,j;
FILE *f_solution;
f_solution=fopen("solution.txt","wb");
if( f_solution == NULL )
{
printf("Le fichier est corronpu");
exit(1);
}
for (i=0; i<n; i++){
for (j=0; j<n; j++){
fprintf(f_solution,"%c\n",grille.data[i][j]);
}
printf("|\n");
}
printf("\n");
fclose(f_solution);
}
Here grille.data is the matrix that i want to save in a file .
The thing is that when i run the code nothing appears no .txt ( I made sure that I was in the correct directory before saying this ) .
Is there anyone with a clue ? Thanks
I did a simplified guess on your structure (not looking at your comments). Assuming that your
datastructure is correctly initilized, then it should print correctly.But since on your end there is a problems getting the file you want, my guess is that
grillecontent (or in combination withn) the data is not properly initialized.E.g. (the simplified version)
The
perrorwould also help in clarifying what (might) be wrong when opening/creating a file.