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

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


        
9条回答
  •  萌比男神i
    2020-12-06 08:27

    The actual meaning of \n is \r+\n. getch() function reads a character from the keyboard.
    It does not echo it and does not wait for next character.
    So whenever we enter \n character getch() function reads \r character only.

提交回复
热议问题