Hi,
I need to read in a formatted file that looks something like this.
Code: HARK
Name: Oscar
MRTE: Train
etc
At the moment my code looks like this.
FILE *file;
char unneeded[10];
char whitespace[2];
char actual[10];
file = fopen("scannertest.txt","r");
fscanf(file,"%s",unneeded); // this is the identifier and the colon (code:)
fscanf(file,"%[ ]",whitespace); // this takes in the white space after the colon.
fscanf(file,"%s",actual); // this is the value I actually need.
/**
* Do stuff with the actual variable
**/
fclose(file);
This way works for me but I don't think writing three fscanf()'s for each line in the text file is the best way to do it, especially as I will be doing it in a loop later.
I tried doing it like this:
fscanf(file, "%s %[ ] %s",unneeded,whitespace,real);
However this gave me weird symbols when I tried printing the output.
Any help is appreciated.
Thanks