Reading \r (carriage return) vs \n (newline) from console with getc?

后端 未结 4 1578
南旧
南旧 2021-01-31 09:04

I\'m writing a function that basically waits for the user to hit \"enter\" and then does something. What I\'ve found that works when testing is the below:

#incl         


        
4条回答
  •  你的背包
    2021-01-31 09:54

    \n is the newline character, while \r is the carriage return. They differ in what uses them. Windows uses \r\n to signify the enter key was pressed, while Linux and Unix use \n to signify that the enter key was pressed.

    Thus, I'd always use \n because it's used by all; and if (x == '\n') is the proper way to test character equality.

提交回复
热议问题