我调试了一晚上,控制台老是跳着问我第二跑者的名字,却不给我输入第一跑者名字的零钱,这很迷惑。
这是我的 main.c 中的部分
Trunner runners[10];
Trunner best;
int n,i;
const char* name = "give the name for runner ";
const char* time = "give the time for runner ";
printf("How many names you have?");
scanf("%d",&n);
for(i=0;i<n;i++){
readTime(&runners[i],time);
}
for(i=0;i<n;i++){
readName(&runners[i],name);
}
这是我的runner.c
void readName(Trunner *runner, const char *prompt){
printf(prompt);
fgets (runner->name,30,stdin);
//getchar();
}
我得到的是,跑步者的名字应该和逗号在同一行,正如你所看到的,第一个跑步者的名字是空的。
How many names you have?3
give the time for runner 11:13
give the time for runner 14:14
give the time for runner 12:13
give the name for runner give the name for runner lily
give the name for runner lucy
the winner is:
, 11:13
, 11:13 0:0
lily
, 14:14 3:1
lucy
, 12:13 1:0
Press any key to continue . . .