Why doesn't pressing enter return '\n' to getch()?

前端 未结 9 1678
忘掉有多难
忘掉有多难 2020-12-06 07:43
#include 
#include 
main()
{
    char ch,name[20];
    int i=0;
    clrscr();
    printf(\"Enter a string:\");
    while((ch=getch())!=         


        
9条回答
  •  遥遥无期
    2020-12-06 08:28

    That is because the return key on your keyboard is represented internally as '\r' not '\n'. In order for that specific example to work, you would need to trap '\r' instead.

提交回复
热议问题