Is there a command that can recognize whether a character in the string is a integer? I have to write a function that does the following:
This function returns true if its parameter is a syntactically valid path, and false otherwise. A syntactically valid path is a sequence of zero or more path segments (not separated by spaces, commas, or anything else). Here are two syntactically valid paths: N2e1E01n0e2e1 and W42. Here are four strings that are not syntactically valid paths: sn3, e1x, N144, and w2+n3. Notice that a path may be syntactically valid without being traversible in a particular grid.
My idea is to read the first character of the string. If it's equal to N,n,S,s,W,w,E,e then it would move on to the next character else the function would return false. Here is where I need a command that can recognize if the character is an integer. If it's an integer it will move on to the next character. If that character is an integer or N,n,S,s,W,w,E,e then it continues to the next character and so on. The function will continue until the index is less than the string size or until it fails a condition test.
Is it possible to use isdigit with a switch/case? I tried the following and it won't let me because
case isdigit(path[index]):
isn't a constant.
switch (path[index])
{
case 'N':
case 'n':
case 'S':
case 's':
case 'W':
case 'w':
case 'E':
case 'e':
index++;
break;
default:
return 0;
}
for(index;index != path.size();index++)
{
switch (path[index])
{
case 'N':
case 'n':
case 'S':
case 's':
case 'W':
case 'w':
case 'E':
case 'e':
case isdigit(path[index]):
break;
default:
return 0;
}
}