Using fseek to backtrack

前端 未结 5 925
轻奢々
轻奢々 2020-12-11 19:18

Is using fseek to backtrack character fscanf operations reliable?

Like for example if I have just fscanf-ed 10 characters but

5条回答
  •  情深已故
    2020-12-11 19:40

    Just tried this with VS2008 and found that fscanf and fseek treated the CR and LF characters in the same way (as a single character).

    So with two files:

    0000000: 3132 3334 3554 3738 3930 3132 3334 3536 12345X7890123456

    and

    0000000: 3132 3334 350d 0a37 3839 3031 3233 3435 12345..789012345

    If I read 15 characters I get to the second '5', then seek back 10 characters, my next character read is the 'X' in the first case and the CRLF in the second.

    This seems like a very OS/compiler specific problem.

提交回复
热议问题