gpt4 book ai didi

c - fgets()在函数中不起作用

转载 作者:行者123 更新时间:2023-12-04 09:24:47 24 4
gpt4 key购买 nike

<分区>

我正在编写一个程序,它使用 fgets() 扫描一个 3 个字符长的字符串作为出发和到达的机场代码。当我在其方法之外(主要)编写语句时,它工作正常,但在内部它不等待输入并将变量留空。

void newFlight ()
{
printf("\n");
printf("============= CREATE A NEW FLIGHT ============= \n");
printf("Type 0 at any point to exit to main menu. \n");
printf("\n");

printf("EnterFlight ID (0 to cancel) : ");
scanf("%d", &flyList[curFly].flightID);

char codeA [4];
printf ("Enter Destination (Airport Code): ");
fgets(codeA, 3, stdin);
strcpy(codeA, flyList[curFly].arrive);
printf("%s %s \n", codeA, flyList[curFly].arrive); //TEST

printf("Enter Place Of Departure: ");
char codeD[4];
scanf("%s", codeD);
strcpy(codeD, flyList[curFly].depart);
printf("%s %s \n", codeD, flyList[curFly].depart); //TEST

printf("Enter Date Of Departure (DD MM YYYY): ");
scanf("%hd %hd %hd", &flyList[curFly].timeOfDep.day, &flyList[curFly].timeOfDep.month, &flyList[curFly].timeOfDep.year);

printf("Enter Time Of Departure (HH MM)in 24Hr Format: ");
scanf("%hd %hd", &flyList[curFly].timeOfDep.hour, &flyList[curFly].timeOfDep.minute);

curFly++;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com