0
我需要關於如何在這個例子中使用isdigit()
一些幫助:使用ISDIGIT C編程
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
int usr_option;
do
{
printf("\t\t\t************************MENU***********************\n");
printf("\t\t\t*** 1. Enter Code\t\t\t\t***\n");
printf("\t\t\t*** 2. Encrypt code and verify if correct\t***\n");
printf("\t\t\t*** 3. Decrypt code\t\t\t\t***\n");
printf("\t\t\t*** 4. Display number of times code was enter\t***\n");
printf("\t\t\t***\t\t(i) Successfully\t\t***\n");
printf("\t\t\t***\t\t(i) Unsuccessfully\t\t***\n");
printf("\t\t\t*** 5. Exit Program\t\t\t\t***\n");
printf("\t\t\t***************************************************\n");
printf("\nPlease enter your option from the menu: ");
scanf("%d", &usr_option);
if (isdigit(usr_option))
{
//Inside here is my switch case e.g switch(usr_option){/*code*/}
}
else
{
printf("Need to enter a digit\n");
}
}//end do while
while(usr_option != 5);
return 0;
}
我怎樣才能實現這個代碼不進入無限循環? 我試過不同的方式,但它似乎不想工作。我使用的編譯器代碼塊和崇高的文本3
你還是應該檢查scanf'的'的返回值。如果它與'1'不同,'usr_option'包含隨機數據。 – IInspectable
感謝您的信息 – Josephy22