I am trying to load a tab and or whitespace delimited text file into a two dimensional array. The file looks something like this:
1 -3 4
4 -3 7
8 -1 10
I have access to a piece of code that suggests it is permissible to do something such as the following:
int nums[][] = {
#include "matrix.txt"
};
However, whenever I try to compile this code I am obtaining the error:
$ gcc hangserver.c
hangserver.c:10:5: error: array type has incomplete element type
In file included from hangserver.c:11:0:
matrix.txt:1:5: error: expected ‘}’ before numeric constant
$
I know there are less-elegant ways to load this file into an array, however out of pure curiosity I would like to know if it is possible to implement the methodology shown above. Thank you so much for taking the time to answer my question.
int nums[][]isn't valid. The maximum of flexibility you can have isint nums[][<some integer>].#includedirective simply places the referenced file into that source file when it's compiled. You could cut+paste the contents ofmatrix.txtintohangserver.cand figure the syntax errors out from there.