I have the following array:
array[];
I take users input as "cd SOMETHING"
The "SOMETHING", should be a number.
BUT if the user enters "cd Hello"
I want to give an error message. Here is the code that i am using to split the user input:
char *arguments[80];
char *split;
split = strtok(userInput," ");
while(split != NULL)
{
arguments[count++] = split;
split = strtok(NULL, " ");
}
Now i have the usersInput stored within my arguments array as:
arguments[0]; (cd) and arguments[1]; (Hello)
Now before I try and pass the arguments to my next function (which needs a number) I need to check if arguments[1]
is a number or the crap that is currently is. Then if it is not a number, display an error message, and if it is a number, I can proceed as I would like to.
I tried both isalpha()
and isdigit()
but they only work for a single char.
I understand that I could loop through argument[1]
and split it into individual chars, then loop through those and check each one with isalpha or isdigit but this is somewhat of a hassle, I would like to know if there is a easier way to do what I am trying to do?