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

后端 未结 4 1493
南旧
南旧 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:43

    The '\n' is the "Line Feed" and '\r' is the carriage return. Different operating systems will handle new lines in a different way, such as

    Windows

    Expects a newline to be combination of two characters, '\r\n'.

    Linux\Unix and Modern Mac OS

    Uses a single '\n' for a new line.

    Classic Mac OS

    Uses a single '\r' for a new line.

    Basically, I would use if (x == '\n') as it is currently used by all modern operating systems.

提交回复
热议问题