Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a portion of my program that is generating an error when I try to compil

ID: 3628705 • Letter: T

Question

This is a portion of my program that is generating an error when I try to compile.

bool symbolTable:: validValueNumber(Line oneString)
{
   >     if(isdigit(oneString))
    return true;
   
    else
    {
        cout << "ERROR - Invalid value number. " << endl;
        return false;
    }
}

The definition of "Line" in the header file is:

const int LINESIZE = 80;
typedef char Line[LINESIZE + 1];

Basically the program reads in values from a file and stores them in a character array, and then for this specific function I need to test if what is stored in oneString is a number. The error generated is:

C:Users******DesktopSymbol TablesymbolTable.cpp In member function `bool symbolTable::validValueNumber(char*)':

82 C:Users******DesktopSymbol TablesymbolTable.cpp invalid conversion from `char*' to `int'

82 C:Users******DesktopSymbol TablesymbolTable.cpp   initializing argument 1 of `int isdigit(int)'

How can I fix this so that it properly tests if oneString is a number and converts it to an integer value?

Explanation / Answer

atoi() returns an int (which the compiler won't let you store in char* without a static_cast, so we introduce a temporary variable to hold the parsed integer): bool symbolTable::validValueNumber(Line oneString) { int parsedDigit = atoi(oneString); if(isdigit(parsedDigit)) return true; else { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote