fgets and dealing with CTRL+D input

前端 未结 1 567
轻奢々
轻奢々 2021-01-14 08:51

I am grabbing some standard input from the user and if the user presses CTRL+D, I want to display an error and terminate the program. I think perhaps my issue may

相关标签:
1条回答
  • 2021-01-14 09:00

    On Linux, Ctrl + D generates EOF, so you need to check the return value of fgets() every time. When EOF is encountered, fgets() returns a null pointer

    if (fgets(buff, 10, stdin) == NULL)
        print_error();
    
    0 讨论(0)
提交回复
热议问题