[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Need Clarification

Newbie

7/11/2008 4:31:00 PM

Can u tell me more abt how did the array a[20] got converted into string
a...!!

To this question some-one answered :

No, it won't convert into string object.
Here the representation of string is as character arrays.

Ok.This part is fine.

It can be classifieds depends on the character used to indicate the end
of the string. "In C it is ASCII-Z representation and end with ASCII
value 0"

Is this comment correct ? I did not find anything similar in the C
standard or am i missing something ?

What about systems that don't use the ASCII character set (say if they
use EBCDIC instead ?)
11 Answers

roberson

7/11/2008 4:53:00 PM

0

In article <g581t2$170$1@aioe.org>, Newbie <newbie@gmail.com> wrote:
>Can u tell me more abt how did the array a[20] got converted into string
>a...!!

>To this question some-one answered :

>No, it won't convert into string object.
>Here the representation of string is as character arrays.

>Ok.This part is fine.

>It can be classifieds depends on the character used to indicate the end
>of the string. "In C it is ASCII-Z representation and end with ASCII
>value 0"

>Is this comment correct ? I did not find anything similar in the C
>standard or am i missing something ?

>What about systems that don't use the ASCII character set (say if they
>use EBCDIC instead ?)

No matter which character set you are using, C strings are stored in
C array of char, and the string may be smaller than the array that it
is stored in. The end of the string (as opposed to the end of the
char array) is the first array entry with numeric value 0; if that
numeric 0 happens to be right at the beginning of the array, then the
string is commonly referred to as being "empty" -- but note that
an "empty" string actually needs to have one value stored in it, the
numeric 0 that marks the end of the string.

--
"I will speculate that [...] applications [...] could actually see a
performance boost for most users by going dual-core [...] because it
is running the adware and spyware that [...] are otherwise slowing
down the single CPU that user has today" -- Herb Sutter

Richard Heathfield

7/11/2008 4:54:00 PM

0

Newbie said:

> Can u tell me more abt how did the array a[20] got converted into string
> a...!!

An array can no more be converted into a string than an egg-box can be
converted into eggs. An array is something you put things in. A string is
something you put.

> It can be classifieds depends on the character used to indicate the end
> of the string. "In C it is ASCII-Z representation and end with ASCII
> value 0"
>
> Is this comment correct ?

No. C does not require implementations to use ASCII. Strings are terminated
by the character with code point 0 in the execution character set.

<snip>

--
Richard Heathfield <http://www.cpax....
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/goog...
"Usenet is a strange place" - dmr 29 July 1999

Ben Bacarisse

7/11/2008 5:17:00 PM

0

Newbie <newbie@gmail.com> writes:

> Can u tell me more abt how did the array a[20] got converted into
> string a...!!
>
> To this question some-one answered :
>
> No, it won't convert into string object.
> Here the representation of string is as character arrays.
>
> Ok.This part is fine.
>
> It can be classifieds depends on the character used to indicate the
> end of the string. "In C it is ASCII-Z representation and end with
> ASCII value 0"
>
> Is this comment correct ? I did not find anything similar in the C
> standard or am i missing something ?
>
> What about systems that don't use the ASCII character set (say if they
> use EBCDIC instead ?)

This seems to be the middle of a conversation but I have no context
for it so all I can say is:

A character array can be said to hold a C string if it has a zero byte
somewhere in it. All C strings are zero terminated. A character
array without a zero byte is just an array of characters. The
character set is not important -- only that the byte that marks the
end be arithmetically zero. All sane character sets ensure that zero
can be used for this purpose.

In fact, an array can hold more than one string, but exactly how many
is a matter of definition. This array:

char my_strings[] = { 'a', 'b', 'c', '\0', 'd', '\0' };

has at least two strings in it: the C expressions my_strings and
my_strings + 4 both point to the start of valid strings (some people
choose to say that my_strings *is* a string -- feel free to do that in
casual conversation, but technically it is a pointer to the start of a
string).

my_strings + 1, my_strings + 2, and so on also point to (the start of)
strings, so that array can be said to hold 5 strings that would
compare as being different. It has two zero length strings
(my_strings + 3 and my_strings + 5) but they compare equal.

Hope that helps.

--
Ben.

Newbie

7/11/2008 5:23:00 PM

0

Ben Bacarisse wrote:
> Newbie <newbie@gmail.com> writes:
>
>> Can u tell me more abt how did the array a[20] got converted into
>> string a...!!
>>
>> To this question some-one answered :
>>
>> No, it won't convert into string object.
>> Here the representation of string is as character arrays.
>>
>> Ok.This part is fine.
>>
>> It can be classifieds depends on the character used to indicate the
>> end of the string. "In C it is ASCII-Z representation and end with
>> ASCII value 0"
>>
>> Is this comment correct ? I did not find anything similar in the C
>> standard or am i missing something ?
>>
>> What about systems that don't use the ASCII character set (say if they
>> use EBCDIC instead ?)
>
> This seems to be the middle of a conversation but I have no context
> for it so all I can say is:
>
> A character array can be said to hold a C string if it has a zero byte
> somewhere in it. All C strings are zero terminated. A character
> array without a zero byte is just an array of characters. The
> character set is not important -- only that the byte that marks the
> end be arithmetically zero. All sane character sets ensure that zero
> can be used for this purpose.
>
> In fact, an array can hold more than one string, but exactly how many
> is a matter of definition. This array:
>
> char my_strings[] = { 'a', 'b', 'c', '\0', 'd', '\0' };
>
> has at least two strings in it: the C expressions my_strings and
> my_strings + 4 both point to the start of valid strings (some people
> choose to say that my_strings *is* a string -- feel free to do that in
> casual conversation, but technically it is a pointer to the start of a
> string).
>
> my_strings + 1, my_strings + 2, and so on also point to (the start of)
> strings, so that array can be said to hold 5 strings that would
> compare as being different. It has two zero length strings
> (my_strings + 3 and my_strings + 5) but they compare equal.
>
> Hope that helps.
>
Thanks You all.The only thing i wanted to know was whether it was right
to say "In C it is ASCII-Z representation and end with ASCII value 0"

My point was the All C guaranteed was that every string is NULL
terminated.It does not require the implementation to use ASCII character
set.

Thanks again for the quick replies.





Ben Bacarisse

7/11/2008 6:01:00 PM

0

Newbie <newbie@gmail.com> writes:
<snip>
> Thanks You all.The only thing i wanted to know was whether it was
> right to say "In C it is ASCII-Z representation and end with ASCII
> value 0"

It may be daft to labour the point (you seem happy with the answers)
but the reason I did not answer this question is that I can't put any
meaning to the words. I can't link the two clauses with "and" and the
only meaning I can give to "ASCII-Z representation" (the number 90)
makes not sense in this context.

One often reads things like "ASCII value 0". But the word "ASCII" has
no meaning here. ASCII value 0 is the value 0. It is a property of
all encodings that "Froodle value 90" is 90. What 90 *means* in the
Froodle character set is, of course, a matter for the Froodle
standards committee. If they decide that the character 'A' is to be
represented by the value 0, then it is not possible to use Froodle as
the execution character set for a C implementation because it is the
value 0 (regardless of any meaning it might have) that terminates
strings in C, and C insists that strings be both zero terminated and
be able to hold the character 'A'.

Anyway, I am glad that you are content. If this is more than you
want to know, I apologise.

> My point was the All C guaranteed was that every string is NULL
> terminated.

Be careful with your terms. Strings are null terminated, not NULL
terminated. NULL is a macro which expands to a pointer --
specifically a null pointer constant. Think of NULL as a noun (it is
the name of a macro after all). The word "null" is an adjective --
you can have a null pointer and a null character is used to terminate
strings.

--
Ben.

Newbie

7/11/2008 6:05:00 PM

0

Ben Bacarisse wrote:
> Newbie <newbie@gmail.com> writes:
> <snip>
>> Thanks You all.The only thing i wanted to know was whether it was
>> right to say "In C it is ASCII-Z representation and end with ASCII
>> value 0"
>
> It may be daft to labour the point (you seem happy with the answers)
> but the reason I did not answer this question is that I can't put any
> meaning to the words. I can't link the two clauses with "and" and the
> only meaning I can give to "ASCII-Z representation" (the number 90)
> makes not sense in this context.
>
> One often reads things like "ASCII value 0". But the word "ASCII" has
> no meaning here. ASCII value 0 is the value 0. It is a property of
> all encodings that "Froodle value 90" is 90. What 90 *means* in the
> Froodle character set is, of course, a matter for the Froodle
> standards committee. If they decide that the character 'A' is to be
> represented by the value 0, then it is not possible to use Froodle as
> the execution character set for a C implementation because it is the
> value 0 (regardless of any meaning it might have) that terminates
> strings in C, and C insists that strings be both zero terminated and
> be able to hold the character 'A'.
>
> Anyway, I am glad that you are content. If this is more than you
> want to know, I apologise.
>

This was enlightening! Thank You.

roberson

7/11/2008 6:25:00 PM

0

In article <87d4lk2td8.fsf@bsb.me.uk>,
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:

>only meaning I can give to "ASCII-Z representation" (the number 90)
>makes not sense in this context.

ASCII-Z is a term that means zero-terminated list of ASCII characters
of indefinite size.

It goes along with ASCII-C (I think it is) that means a list of ASCII
characters prefixed with a size count; I'm not positive as to how big
the count is, but 2 bytes is the figure that comes to mind.

--
"Whenever there is a hard job to be done I assign it to a lazy
man; he is sure to find an easy way of doing it."
-- Walter Chrysler

Keith Thompson

7/11/2008 10:45:00 PM

0

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> In fact, an array can hold more than one string, but exactly how many
> is a matter of definition. This array:
>
> char my_strings[] = { 'a', 'b', 'c', '\0', 'd', '\0' };
>
> has at least two strings in it: the C expressions my_strings and
> my_strings + 4 both point to the start of valid strings

Yes, since 6 is at least two. (I see that you addressed this below.)

> (some people
> choose to say that my_strings *is* a string -- feel free to do that in
> casual conversation, but technically it is a pointer to the start of a
> string).

Yes and no. ``my_strings'' is the name of an object. That object is
an array object, not a pointer object. On the other hand, if the name
``my_object'' is used as an expression, it will usually be implicitly
converted to a pointer value (a char* pointing to the 'a'). On the
other other hand, this conversion doesn't happen if ``my_object'' is
the operand of a unary "&" or "sizeof" operator.

So whether "my_object is a pointer" depends on whether you mean the
object named "my_object" or the expression my_object.

> my_strings + 1, my_strings + 2, and so on also point to (the start of)
> strings, so that array can be said to hold 5 strings that would
> compare as being different. It has two zero length strings
> (my_strings + 3 and my_strings + 5) but they compare equal.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Ben Bacarisse

7/11/2008 11:05:00 PM

0

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:

> In article <87d4lk2td8.fsf@bsb.me.uk>,
> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>
>>only meaning I can give to "ASCII-Z representation" (the number 90)
>>makes not sense in this context.
>
> ASCII-Z is a term that means zero-terminated list of ASCII characters
> of indefinite size.

Ah. Not an abbreviation I've come across. That makes it clear that
the OP was only concerned to know that ASCII is not mandated by C.

--
Ben.

Ben Bacarisse

7/11/2008 11:23:00 PM

0

Keith Thompson <kst-u@mib.org> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> In fact, an array can hold more than one string, but exactly how many
>> is a matter of definition. This array:
>>
>> char my_strings[] = { 'a', 'b', 'c', '\0', 'd', '\0' };
>>
>> has at least two strings in it: the C expressions my_strings and
>> my_strings + 4 both point to the start of valid strings
>
> Yes, since 6 is at least two. (I see that you addressed this
> below.)

I knew I'd have to!

>> (some people
>> choose to say that my_strings *is* a string -- feel free to do that in
>> casual conversation, but technically it is a pointer to the start of a
>> string).
>
> Yes and no. ``my_strings'' is the name of an object. That object is
> an array object, not a pointer object. On the other hand, if the name
> ``my_object'' is used as an expression, it will usually be implicitly
> converted to a pointer value (a char* pointing to the 'a'). On the
> other other hand, this conversion doesn't happen if ``my_object'' is
> the operand of a unary "&" or "sizeof" operator.
>
> So whether "my_object is a pointer" depends on whether you mean the
> object named "my_object" or the expression my_object.

Yes. I did say "the expressions my_strings and my_strings + 4" but
obviously I should have repeated "the expression" in the parenthetical
remark to avoid ambiguity. I'll get the hang of c.l.c eventually.

--
Ben.