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

后端 未结 4 1579
南旧
南旧 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

    Also remember that if you type in 25 characters and Enter, the first getc will not return until all 25 characters have been typed in and you hit Enter. Reading a character at the time it is typed requires platform-specific code. Consequently, you might be better off just reading the entire line by performing fgets into a string, trimming the newline, and processing the input line as a whole.

提交回复
热议问题