How could one handle the following scenario. The User is asked to input his command:
- the user inputs only a digit for example 1
- the user inuts a string for example hello
- the user inuts a string for example hello 1 2
The Terminal could look like
Enter: 1 -- programm do somehting(not important)
Enter: hello -- programm do somehting(not important)
Enter: hello 1 2 -- programm do somehting(not important)
My Code
printf("Enter:");
scanf("%[^\n]s", command_player);
getchar()
for(size_t i = 0; i < strlen(command); i++)
{
if(isdigit(command[i]))
{
has_digit = 1;
}
if(isalpha(command[i]))
{
has_letter = 1;
}
}
and then
if(has_digit == 1 && has_letter == 0)
//do something
if(has_digit == 0 && has_letter == 1)
//do something
if(has_digit == 1 && has_letter == 1)
//do something
However I have the problem that if I enter in one of the ifs another datatype as it is stated my programm crashes