getchar相关问题

想通过一个循环实现程序暂停等待玩家读完内容再继续


void contin()
{
    int stop;
    while (1)  //按回车继续
    {
        printf("\n_____________________________________________\n按回车继续\n");
        printf("按M打开菜单");
        stop = getchar();
        if (stop == '\n')
        {
            putchar(stop);
            break;
        }
    }
}

主函数体中第一次和第三次使用该函数可以实现暂停程序,等待用户输入后继续,但第二次使用不行

尝试更换成getch或gets都失败了

getchar前加一句fflush(stdio);,清除输入缓存,不然getchar会读入上次输入的回车符。