私のプログラムは、実行時に2次元配列にメモリを割り当て、要素を取り込んで表示することを目的としています。私のプログラムはいくつかの例外をスローしていますが、誰かがそれを特定するのを手伝ってくれますか?
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
int main()
{
int i,j,row, col;
int *ptr;
printf("enter size of row and col\n");
scanf("%d%d",&row,&col);
ptr = (int *)malloc(row*col*sizeof(int));
if(ptr==NULL)
{
printf("stderr, not able to allocate memory");
exit(1);
}
else
{
printf("enter the element");
for(i=0; i<row;i++)
for(j=0;j<col;j++)
{
scanf("%d",ptr[i+j]);
}
for(i=0; i<row;i++)
{
for(j=0;j<col;j++)
printf("%d ",ptr[i+j]);
printf("\n");
}
}
}