1
I need to read from a file the amount of tests to be done and which tests to be done. The input file is as follows:
4 //Numero de testes a serem feitos
1 LINSIMP 3 //Primeiro(1) teste que verifica se a linha 3 é simples
2 LINPOL 3 1 //Segundo(2) teste que verifica se a linha 3 intercepta poligono 1
3 POLSIMP 1 //Terceiro(3) teste que verifica se o poligono 1 é simples
4 PTOPOL 1 1 //Quarto(4) teste que verifica se o ponto 1 está no poligono 1
The amount of tests (which are four) has already been implemented through the function:
int LeNumeroDeTestes(FILE *entrada)
{
int numTestes;
fscanf(entrada, "%d", &numTestes);
return numTestes;
}
However, I am having trouble finding a way to read the rest of the input file. I have implemented the following:
int i, LinhaTeste;
char Teste[10];
for(i = 0; i < numTestes; i++)
{
fscanf(entrada, "%d", &i);
fscanf(entrada, "%s", Teste);
if(i == 0)
{
fscanf(entrada, "%d", &LinhaTeste);
printf("%d %s %d", i, Teste, LinhaTeste);
}
}
But it doesn’t look like a very good solution. Also, although no compilation errors occur, nothing is printed on the screen. (I did not finish the cases of i = 1, 2 and 3).
I wish I knew a better way to read this file.
Vc only qr display all its content on the screen or want to display a specific content of it?
– gato
I wanted to display on the screen just to know if I am reading correctly, because actually, it is not necessary to print. What will be printed in the exercise is another content.
– Renan
I’m not understanding q vc qr. Could be more specific regarding your difficulty?
– gato
What I really need is to just read that input file that was specified above. However, I don’t know if I am reading it correctly. The printing part is just to see if I am reading the data correctly. My main question is: How to read input data correctly.
– Renan
Possible duplicate of C problem reading file and writing to vectors/matrices
– Tiago S