views:

136

answers:

4

In C, can I say a white space in a string has a NULL type, or something else?
In C, which character represents the termination of a string?

+11  A: 

The null character (ASCII value 0, '\0' as a character literal) terminates a string in C. This character is not usually regarded as a whitespace character.

The space in the middle of this string for example: "Hello world" is the character with ASCII value 32. This is not the same as NULL or \0.

Mark Byers
In fact the name of the ASCII character that terminates a string is NUL
EvilTeach
+2  A: 

In C, can I say a white space in a string has a NULL type, or something else?

I'm not sure what you mean by a NULL type. A white space is a space character or tab or carriage return.

In C, which character represents the termination of a string?

The '\0' character is the termination of a string.

Starkey
+1  A: 

The termination character is a byte with value 0. Expressed as a literal character, it is '\0'.

Your first question about white space having a NULL type doesn't make any sense.

bstpierre
+1  A: 

The following characters are regarded as "whitespace" in the sense that the isspace() function returns non-zero:

  • space (ASCII 0x32, C literal ' ')
  • tab (ASCII 0x09, C literal '\t')
  • vertical tab (ASCII 0x0B, C literal '\v')
  • form feed (ASCII 0x0C, C literal '\f')
  • carriage return (ASCII 0x0E, C literal '\r')
  • newline (ASCII 0x0A, C literal '\n')

The string terminator is the ASCII NUL (0x00) character; it generally has no effect on the cursor if you attempt to output it to a console or terminal.

Clifford
Trivia: NUL is coded as zero because it corresponds to blank paper tape leader. DEL is coded as 0x7f (or 0xff sometimes) because it corresponds to all holes punched on a paper tape, and it used to be called RUBOUT indicating that it was used to correct mistakes without requiring that an operator repunch an entire tape.
RBerteig
@RBerteig: Interesting. And thanks for thw 'clean-up'
Clifford