Re: chars



Bill Cunningham wrote:
"James Kuyper" <jameskuyper@xxxxxxxxxxx> wrote in message
news:WgCgj.1965$sH.1240@xxxxxxxxxxx
....
"12345\0" is a pointer to the first element of an array of char containing
the following values: {'1', '2', '3', '4', '5', '\0', '\0'}.
The first six characters of that array form a string. However, the array
as a whole is not a single string; it could arguably be called two
consecutive strings.
....
This null terminating string the user never puts into his string right?

That sentence doesn't quite make sense. Null-terminated strings are
terminated, as the name implies, by null characters. A C string
literal has a value which is a pointer at the first element of an
array of char which is automatically null-terminated. A string literal
it can also contain explicit null characters, as in your example.
That's why the corresponding array has two null characters a the end,
not just one.

The compiler, assembler, or linker puts it there everytime right? I have
seen some source where the programmer wants the compiler to put a null
string into the code hence,

char a;
a='\0';

So a contains the value of the null pointer between ' '. If I am reading
correctly.

You're confusing null characters with null pointers, a confusion that
C compounds because a null character constant IS a null pointer
constant, if it appears in a pointer context. This is NOT a pointer
context, so '\0' is a integer constant with a value of 0.

char *pc = '\0'; // pointer context: null pointer constant
*pc = '\0'; // non-pointer context: integer constant

You also seem to be confusing character literals with string literals.
'\0' is a character literal with a value of 0. "hello" is a string
literal. The value of that string literal is a pointer to an array of
six chars, the last of which is a null character. "he\0llo" is a
string literal which points to an array of 7 chars. In that array,
both the 3rd char and the 7th one are null characters. "\0" points to
an array of two chars, both of then null characters. "" points to an
array of 1 char, which is a null character.
.



Relevant Pages

  • Re: Help a beginner - simple lowercase to uppercase and so on function
    ... And then one to loop across the string calling that function ... copying at to a new array. ... are any characters other than lowercase letters */ ...
    (comp.lang.c)
  • Re: fgets question
    ... documentation didn't say if fgets put \0 after a string literal. ... fgets() has nothing at all to do with string literals. ... within the bounds of the array, then it is not a string. ... strlenon an array of characters that is not a string, ...
    (comp.lang.c)
  • Re: Help creating a random string in Perl
    ... can pick one of the 7 characters in my source string) by using "print ... third and fourth characters to and check that the random number hasn't ... shuffling the array ... The idea here is to swap the current cell with some cell ...
    (perl.beginners)
  • Re: newbie: mapping CHARACTER*2 to INTEGER*2
    ... that destroys the Chinese characters in my input. ... effect the conversion required. ... If MOLD is an array and SIZE is omitted, ... represent the values 4.0 and 1082130432 as the string of binary digits ...
    (comp.lang.fortran)
  • Re: Parsing binary values in the registry
    ... how to take a string variable that could concievably be up to 300 ... and split that into either an array or multiple variables for ... every 32 characters within the original varable. ... I am trying to build a file path from a binary value in the ...
    (microsoft.public.scripting.vbscript)