Hi, I want to know what is wrong in this code for reading and printing an array, because it gives "the program stopped working" when I run it.

#include<stdio.h>
int main(void)
{
    int arr[2][3];
    readmat(arr,2,3);
    printmat(arr,2,3);
}
int readmat(int **mat,int m,int n)
{
    int i,j;
    for(i=0;i<m;++i)
    for(j=0;j<n;++j)
    scanf("%d",&mat[i][j]);
}
int printmat(int **mat,int m,int n)
{
    int i,j;
    for(i=0;i<m;++i)
    {
        for(j=0;j<n;++j)
        printf("%d\t",mat[i][j]);   
        puts("\n");
    }
}

There must be a stacktrace. Paste the stacktrace here if possible.

Maybe put the array and indexes in parens after the & ? Debug messages on stderr , which, unlike stdout, is unbuffered!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.