473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need Clarification

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 ?)
Jul 11 '08 #1
11 1251
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.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 11 '08 #2
In article <g5**********@aioe.org>, Newbie <ne****@gmail.comwrote:
>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
Jul 11 '08 #3
Newbie <ne****@gmail.comwrites:
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.
Jul 11 '08 #4
Ben Bacarisse wrote:
Newbie <ne****@gmail.comwrites:
>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.

Jul 11 '08 #5
Newbie <ne****@gmail.comwrites:
<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.
Jul 11 '08 #6
Ben Bacarisse wrote:
Newbie <ne****@gmail.comwrites:
<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.
Jul 11 '08 #7
In article <87************@bsb.me.uk>,
Ben Bacarisse <be********@bsb.me.ukwrote:
>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
Jul 11 '08 #8
Ben Bacarisse <be********@bsb.me.ukwrites:
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) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 11 '08 #9
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <87************@bsb.me.uk>,
Ben Bacarisse <be********@bsb.me.ukwrote:
>>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.
Jul 11 '08 #10
Keith Thompson <ks***@mib.orgwrites:
Ben Bacarisse <be********@bsb.me.ukwrites:
>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.
Jul 11 '08 #11
Ben Bacarisse <be********@bsb.me.ukwrites:
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
>In article <87************@bsb.me.uk>,
Ben Bacarisse <be********@bsb.me.ukwrote:
>>>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.
The term I've seen is "asciz". It is, for example, an assembler
directive; something like
.asciz "hello"
creates a constant containing "hello" followed by '\0', whereas
.ascii "hello"
might create a similar constant without the '\0'. (Not directly
relevant to C, but relevant to understanding what's being discussed.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 12 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jimmy Johns | last post by:
Hi all, I have some class hierarchy as follows: class S {}; class A {}; class B {public: vector<S*> v_; virtual ~B();}; class C : public virtual A, public virtual B { // do I need to define...
3
by: John D. Sanders | last post by:
I have just upgraded MySQL from version 3.23 to version 4.1.8 and now I am getting the following error when I try to run a script that worked: install_driver(mysql) failed: Can't load...
70
by: rahul8143 | last post by:
hello, 1) First how following program get executed i mean how output is printed and also why following program gives different output in Turbo C++ compiler and Visual c++ 6 compiler? void main()...
1
by: Ken | last post by:
Hello Everyone, I would like to use EnumPorts twice on my form. The first time I want to use Port_Info_1 to just list the Port Names. The second instance where I need EnumPorts , is when I...
8
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I...
7
by: raulavi | last post by:
on a msg on 2/20/05 8:16 am pst you state (talking about arguments) >>Depending on the application, certain parameter values need to be put between double quotes, for example, file names containing...
17
by: Alan Silver | last post by:
Hello, I have a generic method in a utility class that grabs an sqldatareader and returns it. Due to the fact that (AFAIK), you can't close the database connection before you've read the data,...
9
by: wizwx | last post by:
what does the following mean? int func2(); According to C++, it surely means func2 is a function that takes no argument and returns an integer. But what about in C? Does it have the same...
3
by: a | last post by:
Hi, I need clarification for virtual method and pure virtual method. e.g Class Base{ virtual void func(){ ---- } } Class Child : public Base{ void func()
2
by: ravir | last post by:
Hi, I am new to this group. I am working in Perl and shellscripts. I have a clarification regarding perl grep and pattern matching. I am writing a perl script to automate the process of code...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.