I want to write an array in a .txt file but I can not find a way to do it. My code writes the matrix but in a linear way.
#include <stdio.h>
int main(){
int arreglo[3][3] = {{'1','2','3'},{'4','5','6'},{'7','8','9'}};
int largo = 3;
FILE *fichero;
fichero = fopen("arreglo.txt","w+");
fwrite(arreglo, sizeof(char), sizeof(arreglo), fichero );
fclose(fichero);
return 0;
}
What this code writes to me is:
1 2 3 4 5 6 7 8 9
But I need you to be like this:
1 2 3
4 5 6
7 8 9
I do not know if I should use another function besides fwrite () for the line break "\ n" try two for cycles but it does not work for me. It's a basic question but I'm lost.