为什么我的scanf_s()在切换后忽略...情况

时间:2019-05-19 10:04:38

标签: c

如我的问题所述,在我的情况下,我的scanf_s()立即被忽略,这是我的代码。

试图使用scanf_s(" %c",&choice)但仍然被忽略了吗?

#include<stdio.h> 

void main() {
    //Main Function//
    int menuinput;
    char choice; 
    flag = true; //ignore the flag
    printf("----WELCOME TO INVENTORY MANAGEMENT SYSTEM---- \n");

    do{

        printf("\n");//looped to here
        printf("Please choose from below menu by inputting a number of choice \n");

        scanf_s("%d",&menuinput);


            switch(menuinput)
            {
            case 1:
                printf("Input is 1");
                break;
            case 2:
                printf("Input is 2");
                break;
           default:
                printf("Input is wrong");
            }

        printf("\nDo you want to continue?(y/n)\n");
        scanf_s("  %c", &choice );

        switch(choice)
        {
        case 'y':
            flag = true;
            break;
        case 'n':
            flag = false;
            break;
        default:
            printf("Please Input y/n");
            break;
        }

    } while (flag == true);
    getch();
}

如何阻止它被忽略,并给我一种输入我想要的值的方法?

0 个答案:

没有答案