I'm really a beginner in C programming language, and i've started learning pointers... I have some problems manipulating them. What i want to do is to read and write a matrix, with 2 functions, without using global variables (just pointers)... So I did not succed making this. I've searched a lot about pointers and I try to understand how i can use them , but i'm not able to read and write that matrix What i do wrong ...Please, please, please help me (Even with some Useful links about 2DArray & pointers)...Thank you!
#include <stdio.h>
#include <stdlib.h>
void readM(int (*x)[100][100], int *row, int *column)
{
int i,j;
printf("Row no: ");
scanf("%d",row);
printf("Column no: ");
scanf("%d",column);
printf("Matrix elemnts: \n");
for(i=0;i<(*row);i++)
{
for(j=0;j<(*column);j++)
{
printf("[%d][%d]=",i,j);
scanf("%d",x[i][j]);
}
}
}
void writeM(int (*x)[][100], int *row, int *column)
{
int i,j;
printf("\nMatrix is: \n");
for(i=0;i<(*row);i++){
for (j=0;j<(*column);j++){
printf("%d",(*x)[i][j]);
}
printf("\n");
}
}
int main()
{
char choice;
int a[100][100],m,n;
do
{
printf("\nChose an option\n\n"
"1) read matrix \n"
"2) write matrix\n"
"3) display matrix in spiral\n"
"4) return max and min\n"
///...etc
scanf("%c", &choice);
while (choice<'0'|| choice>'4')
{
printf("\nInvalid option! Chose again! \n\n");
scanf("%c",&choice);
}
switch (choice)
{
case '0': exit(0);
case '1': readM(&a,&m,&n); break;
case '2': writeM(&a,&m,&n);break; /// ... etc
} while (choice !=5);
getch();
}