Re: chars



On Jan 7, 12:20 pm, "Bill Cunningham" <nos...@xxxxxxxxx> wrote:
    OK this thing about chars. So a string and a char is two different
things. This is the way I'm understanding things:

char c; is actually a short or int

c is neither a short nor an int. It is a {usually} different sized
integer, and is {usually} smaller than short even though it does not
have to be. But your notion (I think) is that a char can be
considered a very small integer type and that is correct.

char *s; s is a pointer to a char and to be used for strings

It does not have to be used for strings. It could point to a single
character. It is simply the place to store the address of one or more
characters.

char foo[5]; is an array used to store so much info.

The array foo stores 5 characters, which could be a string if it were
zero terminated.

    Do I sound like I'm getting it right now?

Not sure. A string (in C) is a pointer to an array {or an array} of
zero or more characters with a terminating zero.

So this is a string:

char *foo = "I am a string";

and this is a string:

char bar[4] = "123";

but this is not a string, it's just an array because it does not have
a terminating zero:

char barbad[4] = "1234";

and neither is this:

char badbar[3] = {'a', 'b', 'c'};

Does it seem clear?

.



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)