I need to read in a formatted file that looks something like this.
At the moment my code looks like this.
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
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.
以上就是Is there a more efficient way of reading a formatted file in C than I have done?的详细内容，更多请关注web前端其它相关文章！