I wrote a C program to create an array of pointers and each of the individual pointers will in turn be separate arrays(somewhat like a 2D array). I wrote the following C code but it doesn't work.
#include<stdlib.h>
#include<conio.h>
int main(void)
{
int rows=5,cols = 5;
int *a[100];
int i = 0;
int j;
int k = 0;
int b[100];
while(i<rows)
{
printf("\nEnter the %d row: ",i);
for(j=0;j<cols;j++)
scanf("%d",&b[j]);
a[k++] = b;
i = i + 1;
}
k = k-1;
for(i=0;i<=k;i++){
for(j=0;j<cols;j++){
printf("%d ",a[i][j]);
}
}
getch();
return 0;
}
I want something like a 5*5 matrix structure but I want to manipulate each row as if they were a one dimensional array . Can someone tell me how to do that?