0
I need to read txt files in C and interpret the data from inside the files. The files contain parts in TEXT and others in DECIMAL/INTEGER numbers. What I need to do is read the whole file and pass the numbers to a Cartesian coordinate structure. For example, the contents of the file are:
NAME : eil8
COMMENT : 8-city problem (Christofides/Eilon)
TYPE : TSP
DIMENSION : 8
EDGE_WEIGHT_TYPE : EUC_2D
NODE_COORD_SECTION
1 37 52
2 49 49
3 52 64
4 20 26
5 40 30
6 21 47
7 17 63
8 31 62
EOF
I need to read and allocate the data from
1 37 52
2 49 49
3 52 64
4 20 26
5 40 30
6 21 47
7 17 63
8 31 62
EOF
in a structure so that it looks more or less like this:
coordenada.x[1] = 37;
coordenada.y[1] = 52;
coordenada.x[2] = 49;
coordenada.y[2] = 49;
...
But I don’t have enough knowledge about dynamic allocation. What I thought:
1- abrir o arquivo
2- ler o arquivo linha por linha até encontrar "NODE_COORD_SECTION"
3- ler o arquivo linha por linha
4- alocar dinamicamente os dados em uma estrutura tipo matriz x * y
5- parar em EOF
I have knowledge of the code up to the reading part of the file, but as each file will have a different number of lines, how to do this reading without a predefined size?