Hi guys, I'm trying to learn how to read and print a matrix using C. I wrote the following code. However, the compiler gave me this error.
tutorial_10_qn3_tryagain.c: In function `readMatrix':
tutorial_10_qn3_tryagain.c:28: error: parse error before '(' token
tutorial_10_qn3_tryagain.c: In function `printMatrix':
tutorial_10_qn3_tryagain.c:36: error: parse error before '(' token
I'm not sure what's wrong. I counted the brackets and made sure I did not miss out any, neither did i miss out ';'. Can you please advise what's wrong. thanks.
Code:
#include <stdio.h>
struct Matrix
{
int rows; int columns;
int mat [10][10];
};
void readMatrix (struct Matrix *M);
void printMatrix (struct Matrix M);
int main ( )
{
struct Matrix M ={0,0,{{0}}}, *ptr;
ptr= &M;
readMatrix(&M);
printMatrix(M);
return 0;
}
void readMatrix ( struct Matrix *M)
{
int i=0; int j=0;
scanf("%d %d", &((*M).rows), &((*M).columns));
for ( i=0; i<((*M).rows); i++)
for (j=0; j<((*M).columns); j++)
scanf("%d",& ((*M).(mat[i][j])));
}
void printMatrix (struct Matrix M)
{
int i=0; int j=0;
for (i=0; i<(M.rows); i++)
{
for (j=0; j<(M.columns); j++)
printf("%d", (M.(mat[i][j])));
printf("\n");
}
}