コードに少し問題があります。ここで行っているのは、基本的に入力検証に ASCII を使用することであり、while ループがなくても問題なく動作しますが、while ループを使用すると 1 回は完全に実行されますが、コードの先頭に戻ると動作が停止しますつまり、すべてが無効な入力であると想定されます。
void menu()
{
char userInput[10] = {0};
int asciiCode[10];
int i;
int countZero = 0;
int storeUserOption;
while (storeUserOption !=1 && storeUserOption !=2 && storeUserOption !=0)
{
printf("\nPlease enter any of the following options:\n");
printf("\nEnter winning number (w)\n");
printf("\nEnter ticket numbers (t)\n");
printf("\nquit (q)\n");
printf("\n>: ");
fgets(userInput, 10, stdin);
/*It converts whatever I type in asciiData, and see if there's left over data*/
for (i = 0; i < 10; i++)
{
asciiCode[i] = userInput[i];
if (asciiCode[i] == 0)
{
countZero++;
}
}
/*It takes left over data and subtracts it by 10 to reSize it*/
int reSize = (10 - countZero);
/*It checks to see if you enetered anything more than 2 element if so it will input
invalid input. For example can input dd, but can't input asdadasdasd*/
if (reSize > 2)
{
printf("Invalid Input1.");
}
/*If there's two elements left inside the array*/
else if (reSize == 2)
{
if (asciiCode[0] == 119)
{
printf("You have entered w");
storeUserOption = 1;
}
else if (asciiCode[0] == 116)
{
printf("You have entered t");
storeUserOption = 2;
}
else if (asciiCode[0] == 113)
{
printf("You have entered q");
storeUserOption = 0;
}
else{
printf("Invalid Input.");
}
}
}
}