trying to scan in to a 2-d malloc'd array c programming -
i've looked through quite few questions of 2-d malloc'd arrays bascially whatever reason cannot find solution.... google fu sux sorry =(. been using site day syntactual help though helps here! =)
anyways cant seem fscanf work =/ if help me much appreciated because cant see error @ know there 1 because @ point programme crashes.
array1 = (int**)malloc((c)*sizeof(int*)); int = 0, = 0; (a = 0; < c; a++){ array1[a] = (int*)malloc((c+1)*sizeof(int)); } a=0; for(a = 0; < c; a++){ for(i = 0; < c; i++){ fscanf(ifp, "%d", array1[a][i]); } }
where c maximum size of array needed. in case set 3 need variable
when using scanf
family of function read value, destination needs pointer. array1[a][i]
not pointer, actual value (which scanf
treat pointer , entered territory of undefined behavior).
what want &array1[a][i]
.
ps. should not cast returned value of malloc
.
c
No comments:
Post a Comment