I have a problem with the fscanf function
Excuse my bad english.
The program reads the file as follows:
status = fscanf(ifile, "%%!%11s", ifbuf);
if the file starts directly with the desired entry, eg
%! UTF-8
some text
fscanf reads a line in ifbuf.
If in the line starts with whitespaces
%! UTF-8
some text
fscanf does not read anything.
Making the fscanf function work in both cases can be done by adding a space in the format string:
status = fscanf(ifile, " %%!%11s", ifbuf);
I wanted to know how correct the behavior of the fscanf function is.
What you describe as the observed behaviour is the correct behaviour. The
scanf()functions only skip leading white space on some (most — all but%cand%[, in fact) conversion specifications. For literal components of the format string, it behaves more or less literally, except that a space in the format string matches any number of white space characters in the data.