I am trying to take integer data and store it into a dimensional array but i am unable to do it. Somebody help me please..
I tried using *(*(arr+i) + j)
where arr is a pointer to the 2-D array , i
and j
are the loop variables,
I get an error
error: invalid type argument of unary '*' (have 'int') scanf("%d", ((arr+i) + j));
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
int n,*arr,i,j,k;
scanf("%d",&n);
arr = malloc(n*n*sizeof(int));
memset(arr,0,n*n*sizeof(int));
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d", *(*(arr+i) + j));
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%d ", *(*(arr+i) + j);
}
printf("\n");
}
}
My input was:
3
11 2 4
4 5 6
10 8 -12