I’ve got to parse a .txt file like this
autore: sempronio, caio; titolo: ; editore: ; luogo_pubblicazione: ; anno: 0; prestito: 0-1-1900; collocazione: ; descrizione_fisica: ; nota: ;
with fscanf in C code.
I tried with some formats in fscanf call, but none of them worked…
EDIT:
a = fscanf(fp, “autore: %s”);
This is the first try I did; the patterns ‘autore’, ‘titolo’, ‘editore’, etc. must not be caught by fscanf().
Generally speaking, trying to parse input with
fscanfis not a good idea, as it is difficult to recover gracefully if the input does not match expectations. It is generally better to read the input into an internal buffer (withfreadorfgets), and parse it there (withsscanf,strtok,strtoletc.). Details on which functions are best depend on the definition of the input format (which you did not give us; example input is no replacement for a formal specification).