user6161
user6161

Reputation: 289

char const too long in "C"

I'm getting an char const too long error on if statement. I searched this error in Google, they suggested to change the single quotes('') to double quotes ("") i.e charRead != "/0".

After compiling the code I'm getting a different error that "operands of "!=" not same type".

How to resolve this?

if( (charRead != '/0') && (isalnum(charRead) || isspace(charRead) || ispunct(charRead)) ) ...

Upvotes: 1

Views: 1143

Answers (2)

chmike
chmike

Reputation: 22174

/0 are two chars. This is why you get the error message that it is too big to be stored in a char. \0 is one char which has the byte value 0. This one can be stored in a char.

Upvotes: 4

nos
nos

Reputation: 229244

'/0' is not a valid char literal. If you meant it to be a zero byte, you escape it with backslash, like so: '\0'

Upvotes: 4

Related Questions