I am very new to the programming. Please don't be too harsh on me.^^
I allocate two dimensional array, get an input and want to printf the data.
Could you tell me what may be wrong with this code, other than not freeing memory?
The code compiled ok. Two scanfs work fine.
Error occurs at the last printf on main, when I print out the math data.
The error message says "access violation", which I don't understand why.
BTW, I am using VC6.0.
Code:
#include<stdio.h>
#include<stdlib.h>
void getdata(int **a){
int num_data=0,i;
printf("Input the number : ");
scanf("%d",&num_data);
/* allocacate two D. */
a=(int **)malloc(num_data*sizeof(int*));
for(i=0 ; i<num_data ; i++){
a[i]=(int*)malloc(3*sizeof(int));
}
printf("Math: ");
scanf("%d",&a[0][0]);
/* I know I have to delocate the memory somewhere. */
}
int main(){
int **a;
getdata(a);
printf("%d\n",a[0][0]); /* error */
return 0;
}