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