initialize an array reading a .dat file
Hi all I have generate a initial state of a sudok using the following code. Every triplet is translated to row,column,value. For example : 1,1,5 means row=1 column=1 value=5 [code] #include <stdio.h> unsigned char arr[] = { 1,1,5,1,3,2, 2,6,9,2,7,8, 3,2,8,3,4,6,3,6,1,3,7,5, 4,2,5, 5,1,3,5,5,1,5,8,6,5,9,5, 6,3,9,6,5,3,6,8,4,6,9,1, 7,3,4,7,5,6,7,7,1, 8,5,8, 9,4,3,9,5,4,9,6,2,9,8,8}; int main (int argc, char **argv) { FILE *fp; fp = fopen ("initial.dat", "wb"); fwrite (arr, 3, 44, fp); fclose (fp); } [/code] I would like to make a program just read the file (dynamically with malloc) and assign the values to an array[9][9] . So, after the read array[0][0]=5 array[0][2]=2 array[1][5]=9 ... array[8][7]=8