1

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?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Haris Irshad
  • 191
  • 1
  • 4
  • 12
  • Note that the space character has value 32, so isspace cannot only work for numbers up to 8 – smac89 Oct 18 '15 at 06:00

3 Answers3

2

Because according to issspace(), 10 (0xa) is a whitespace character (newline/linefeed). See http://www.cplusplus.com/reference/cctype/isspace/

Dronz
  • 1,970
  • 4
  • 27
  • 50
1

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.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
1

The numbers you are passing are being treated as ASCII characters' numerical representation. 10 is a newline character which is considered by the system to be a white space character.

Laserbeak
  • 78
  • 5