How to display a matrix in C
c, matrix, printing
Solution
Try this simple code
int row, columns;
for (row=0; row<numberOfLines; row++)
{
for(columns=0; columns<numberColumns; columns++)
{
printf("%d ", matrix[row][columns]);
}
printf("\n");
}
Problem
I have a matrix.txt file wherein there is a matrix written this way : ``` 1 2 3 4 5 6 7 8 9 ``` I need to write a little C program that take this file as input and print this matrix in the same way as the .txt file. That means when the outpout of "./a.out matrix.txt" has to be exactly what's in my .txt file : ``` 1 2 3 4 5 6 7 8 9 ``` My problem is that all that I can do is this function: ``` void printMatrice(matrice) { int x = 0; int y = 0; for(x = 0 ; x < numberOfLines ; x++) { printf(" ("); for(y = 0 ; y < numberOfColumns ; y++){ printf("%d ", matrix[x][y]); } printf(")\n"); } } ``` But this is not good at all. Anyone has an idea ? Thanks