c++whitespaceisspace

isspace() only works for digits up to 8?


In my code :

cout << "Isspace 5 and 10 are " << isspace(5) << " and " << isspace(10) << endl;

gives 0 and 8. Why does isspace(10) not give 0 since 10 is not a white space?


Solution

  • You're supposed to pass characters to isspace, not integers.

    isspace('5') == zero (false)
    isspace(' ') == non-zero (true)
    

    When you pass 5 and 10 you're asking it if the characters with ASCII values 5 (ENQ, some rarely used control code) and 10 (LF, line feed, AKA '\n') are whitespace. ENQ is not whitespace, so isspace returns zero. A line feed is whitespace, so isspace returns a non-zero value.