. a char int int. BAD_RETURN = 10, "0" "9". cplusplus.com.
int CharToInt(char ch)
{
return((ch >= '0' && ch <= '9') ? ch - '0' : BAD_RETURN);
}
This is my own function that works in the VS2015 compiler. Define an int array and initialize it to 0s. Pass this int array along with the char prototype array to the following function. This function converts the char array to an int array using the CharToInt function:
void copyCharArrToIntArr(char from[MAX], int to[MAX])
{
for (int i = 0; i < MAX; i++)
to[i] = CharToInt(from[i]);
}
This approach will work with vectors. Instead of MAX, use a i < yourVector.size()for-loop condition for it.
source
share