Is null and space are same?

Is there difference between '\n' and space?
If there is difference that what symbol is used for space?
'\n' is a line feed; basically an enter.
' ' is a space and represents...well, a space. The character used to separate words, etc.
\n is not null; it is the newline character, i.e. it brings the cursor to the next line.

And yes, \n and space are represented by different ASCII and Unicode numbers. I believe \n is 10 (0x0A) and space is 32 (0x20).

FYI, there are three common types of null in C++:
'\0' - The null-terminating character often used in C-strings and string objects. The ASCII value of '\0' is 0.
NULL - A macro that represents 0 for special cases. Before C++11, NULL was used for nullifying pointers.
nullptr - A new nullifier introduced in C++11 specifically for pointers. It is of type nullptr_t.
As already said, \n is not null, but a line feed(new line character) mostly for linux systems whiles \r\n is its windows equivalent.

Aceix.
closed account (zb0S216C)
http://www.asciitable.com/

Wazzak
Note that '\n' is used as the line feed when writing to the console/terminal on all platforms. The platform specific '\n' (*nix/OS-X) vs "\r\n" (DOS/Windows) vs '\r' (pre-OS X Macs) are only relevant when writing to file, or when setting multi-line text in Win32 controls (e.g. Edit control).

Also, when coding for windows, an ofstream opened for text will usually automatically map '\n' to "\r\n" for you when you write a file. And ifstream provides the reverse mapping. So you only need to worry about the "\r\n" if you're treating a text file as binary. (Of course, if you want to write a *nix compatible text file, you need to disable this mapping.)

Andy

PS '\t' (the tab char -- ascii 9) also displays as spaces. And isspace('\t') evaluates as true.
Last edited on
Topic archived. No new replies allowed.