我最后的fgets被跳过为什么?

时间:2017-10-15 16:27:12

标签: c linux netbeans software-design

我正在为我的大学课程编写项目的第二部分。这次我们正在使用循环,而循环。我在循环中的第一个 fgets 运行,其余的也是如此,尽管我不时遇到问题。但是最后一个采用 循环 变量并在提示永远不会运行后更改它。为什么?

我知道这是一个常见问题,但我无法在其他问题上找到解决问题的方法。

printf("Would you like to place an order? Enter 'yes'"
    "\n If not, Enter 'XXX':\n");
fgets(loop, sizeof(loop),stdin);

while(strcmp(loop,"XXX")!=0){

    printf("Please provide your company name: \n");
    fgets(company_n, sizeof(company_n), stdin);

    printf("Please provide name: \n");
    fgets(contact_name, sizeof(contact_name), stdin);

    printf("Please provide contact number: \n");
    fgets(tel_num, sizeof(tel_num), stdin);

    //Items//
    printf("\t\t\t\t  Our Apparels: \n");
    printf("\t\t\tApparels\t\tItem code\n");
    printf("\t\t\ta)T-Shirts\t\t'T'\n");
    printf("\t\t\tb)Bags\t\t\t'B'\n");
    printf("\t\t\tc)Caps\t\t\t'C'\n\n");

    //reading item code//
    printf("Enter corresponding item code: \n");
    scanf(" %c",&code);

    printf("How much of this item would you like to order:\n");
    scanf("%i",&amount);

    printf("Would you like to place another order? Enter 'yes'"
    "\n If not, Enter 'XXX':\n");
    fgets(loop, sizeof(loop),stdin);
}

0 个答案:

没有答案