在第二回循环中fgets跳过
在第二次循环中fgets跳过
linux环境下
char infomsg[][50] = {
"Intput account no.",
"Intput account name.",
"Intput sex[0:male, 1:fmale].",
"Intput transcation amount.",
"Intput transcation type."
};
while(state<=5)
{
setbuf(stdin, NULL);
fprintf(stdout, "%s\n", infomsg[state - 1]);
if (fgets(buffer ,sizeof(buffer), stdin) == NULL)
{
return 0;
}
swtich(state){
case 1:
if(条件){
...
state++;
}
break;
}
case 2:
if(条件){
...
state++;
}
break;
}
case 3:
if(条件){
...
state++;
}
break;
}
case 4:
if(条件){
...
state++;
}
break;
}
case 5:
if(条件){
...
state++;
}
break;
}
}
我在第一轮循环时,我都可以输入,第二次在循环时,直接跳过了account no的输入,就像fgets()没有执行,求高手解
Intput account no.
123123123
Intput account name.
asfsdaf
Intput sex[0:male, 1:fmale].
1
Intput transcation amount.
123
Intput transcation type.
sdf
A new record?[y/n]
y
Intput account no.
Intput account name.
asfsdaf
------解决方案--------------------
单步调试,看看跳过了第二次输入的时候,那个fgets是否获得了一个回车键??
------解决方案--------------------
linux环境下
char infomsg[][50] = {
"Intput account no.",
"Intput account name.",
"Intput sex[0:male, 1:fmale].",
"Intput transcation amount.",
"Intput transcation type."
};
while(state<=5)
{
setbuf(stdin, NULL);
fprintf(stdout, "%s\n", infomsg[state - 1]);
if (fgets(buffer ,sizeof(buffer), stdin) == NULL)
{
return 0;
}
swtich(state){
case 1:
if(条件){
...
state++;
}
break;
}
case 2:
if(条件){
...
state++;
}
break;
}
case 3:
if(条件){
...
state++;
}
break;
}
case 4:
if(条件){
...
state++;
}
break;
}
case 5:
if(条件){
...
state++;
}
break;
}
}
我在第一轮循环时,我都可以输入,第二次在循环时,直接跳过了account no的输入,就像fgets()没有执行,求高手解
Intput account no.
123123123
Intput account name.
asfsdaf
Intput sex[0:male, 1:fmale].
1
Intput transcation amount.
123
Intput transcation type.
sdf
A new record?[y/n]
y
Intput account no.
Intput account name.
asfsdaf
------解决方案--------------------
单步调试,看看跳过了第二次输入的时候,那个fgets是否获得了一个回车键??
------解决方案--------------------