Why doesn't getchar() wait for me to press enter after scanf()?

前端 未结 10 890
悲哀的现实
悲哀的现实 2020-11-22 16:22

I am learning C and I\'m using \"getchar()\" to stop the command windows so I can see the exercises am doing but it just doesn\'t work. heres a sample:

#incl         


        
10条回答
  •  甜味超标
    2020-11-22 17:06

    you are getting a carriage return, the way i would get around it, define a char and just have it scan the carriage return,

    char ch; (before your getch() enter the following) scanf("%c",&ch); getchar();

    should work this way, not the most efficient way to do this but works for me.

提交回复
热议问题