\377 character in c

前端 未结 2 1819
心在旅途
心在旅途 2021-01-19 05:39

i am trying to read a file in c. i have a .txt file and it has that content:

file_one.txt file_two.txt file_three.txt file_four.txt

when i try to read this

2条回答
  •  面向向阳花
    2021-01-19 06:17

    The \377 is an octal escape sequence, decimal 255, all bits set. It comes from converting EOF - which usually has the value -1 - to a char, due to

    while (!feof(filelist)) {
    

    feof(filelist) only becoming true after you have tried to read past the file.

    So at the end of the file, you enter the loop once more, and the getc() returns EOF.

提交回复
热议问题