所以第一部分是我从用户那里得到一个输入,在这个例子中是'1'作为从另一个函数接收的字符值。
printf ("\nPlease enter 1, 2, 3 or q: ");
option = validateoption();
在 validateoption 函数中:
int validateoption () { // VALIDATE OPTION FOR FIRST MENU INPUT
int keeptrying = 1, rc;
char after, i;
do
{
rc = scanf ("%c%c", &i, &after);
if (i == 'q')
{
break;
}
else if (rc == 0)
{
printf (" **Invalid input try again: ");
clear();
}
else if (after != '\n')
{
printf (" **Trailing characters try again: ");
clear();
}
else if (i < '1' || i > '3')
{
printf (" **Invalid input try again: ");
}
else
{
keeptrying = 0;
}
} while (keeptrying == 1);
return i;
}
所以输入字符值'1'然后调用事务函数
do
{
transaction(accounts, debcred, amount);
} while (option == '1');
这就是问题发生的地方。在事务函数中,它有一个 for 循环
for (i = 0; i < MAX; i++)
{
printf ("Enter an account number (between 1000 and 3999): ");
accounts[i] = validateaccount();
debcred[i] = validatedebcred();
amount[i] = validateamount();
totalinput++;
}
它调用 validateaccount 函数来获取有效输入。但是在这个函数中:
int validateaccount() { // VALIDATE INPUT FOR ACCOUNT # IN TRANSACTION FUNCTION
int keeptrying = 1, rc;
long i;
char after;
do
{
rc = scanf ("%ld%c", &i, &after);
if (rc == 0)
{
printf (" **Invalid input try again: ");
clear();
}
else if (after != '\n')
{
printf (" **Trailing characters try again: ");
clear();
}
else if (i < 1000 || i > 3999)
{
printf (" **Invalid input try again: ");
}
else
{
keeptrying = 0;
}
} while (keeptrying == 1);
return i;
}
我输入一个输入,然后程序停止运行!我会像 1000 一样输入,然后它就什么也不做。它并没有结束它只是什么都不做,然后输入更多的数字,它变成一个无效的输入!我不知道发生了什么有人可以看到问题吗?