gpt4 book ai didi

c - fgets() 跳过

转载 作者:行者123 更新时间:2023-12-01 06:14:38 28 4
gpt4 key购买 nike

<分区>

我正在为学校编写一个程序,用户可以在其中输入姓名、工作时间和小时工资。

int main ()
{
char name[SIZE];
char selection = 'Z';
int hoursWorked = 0,
counter = 0,
flag = 1;
float hourlyRate = 0.0;
const float otRate = 1.5;
const int week = 40;

while (flag == 1)
{
system ("cls");
printf ("\n\tP A Y R O L L P R O G R A M\n");
printf ("---------------------------------------------\n");
printf ("\t(A) - New Payroll Info\n\t(B) - Display Payroll\n\t(C) - Quit\n\t");
scanf (" %c", &selection);
selection = toupper (selection);
switch (selection)
{
case 'A':
system ("cls");
printf ("Enter Employee Name: ");
fgets ( name, SIZE, stdin );
strip_newline( name, 50 );
printf ("\nEnter Hourly Rate: ");
scanf ("%f", &hourlyRate);
printf ("\nEnter Hours Worked This Week: ");
scanf ("%d", &hoursWorked);
system ("pause");
break;

SIZE 为 50,包括 stdio.h 和 stdlib.h。当我编译并移至 A 开关时,它会跳过 fgets() 输入并直接进入 "Enter Hourly Rate: " scanf()。我曾尝试更改将 scanf() 放在 fgets() 前面的顺序,但无济于事。

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