C reading (from stdin) stops at 0x1a character

前端 未结 5 540
名媛妹妹
名媛妹妹 2020-12-06 15:39

currently I\'m implementing the Burrows-Wheeler transform (and inverse transform) for raw data (like jpg etc.). When testing on normal data like textfiles no problems occur.

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 16:22

    Use read() to read in the data.
    Since you are interested in getting data from the stdin, use

    fd = fcntl(STDIN_FILENO, F_DUPFD, 0);

    to obtain the fd of stdin.

    More info here.

    The issue has something to do with the fact that windows treats 0x1a a.k.a. CTRL+Z as the EOF. As Earlz pointed out, opening it in binary mode fixes this on windows and works on linux too.

提交回复
热议问题