-
Quick Sizeof Question
At the top of my program I created a definition:
Code:
#define CRLF "\r\n"
Which seems to work just fine except for the fact that the sizeof(CRLF) returns 3 when I would expect the result to be a 2. Is this just a mistake on my part?
Thanks,
PetrolMan
-
Code:
\r = 1
\n = 1
\0 = 1
----
3
-
\0 is a Null Character Right?
Is there a way to prevent the \0 from being put in or is that even desirable in the first place?
PetrolMan
-
Every "string literal" ends with a null character. Whether you want that or not depends on how you use CRLF.
-
There's a multicharacter constant:
Code:
#define CRLF '\r\n'
However that's implementation-defined behaviour, and wont be a direct replacement because then suddently it's not even an array.
I don't think it makes sense to use sizeof on it. If you'd rather avoid using strlen on it, then just declare another constant with the value 2.