so I am having troubles reading a text file. I am very new to code, and I would like my code to be able to read the simple .txt file and store some things: the name of a person, the time (nr after the name), among others.
My txt file has this format:
txt file
I need to store the name of a person, which is located after a "."
and before a ":"
symbol:
- Pedro Mendes: 45
For exame, in this line I need to store "Pedro Mendes".
My code is not working properly:
FILE *f;
f = fopen(filename,"rt");
if(f==NULL){
printf("Erro no acesso ao ficheiro.\n");
return NULL;
}
(...)
while(fgetc(f) != '.'); // finds the point
fscanf(f," %s %s",pnome,unome); //saves the name of a person
while(fgetc(f) != ':');
fscanf(f,"%d",&tempo);
I should get "Pedro Mendes"
but I have "Pedro Mendes:"
, and for the time I should get 45
but I have 46
(is reading from the next line I believe).
If anyone has answers that would be great, thanks.