473,408 Members | 2,832 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,408 software developers and data experts.

about string and character

what is the difference between a single character and a string
consisting only one character
Nov 24 '07 #1
66 3069
In article
<bf**********************************@s19g2000prg. googlegroups.com>,
da****@gmail.com <da****@gmail.comwrote on Saturday 24 Nov 2007 2:57
pm:
what is the difference between a single character and a string
consisting only one character
Try this program:

#include <stdio.h>

int main(void) {
char c0 = '0';
char c1[] = "0";

printf("Size of c0 is %u\nSize of c1 is %u\n", sizeof c0, sizeof c1);
return 0;
}

What is the output and why are the sizes for 'c0' and 'c1' different?
What does your C textbook say?

And try this one too:

#include <stdio.h>

int main(void) {
printf("Size of 'a' is %u\nSize of \"a\" is %u\n",
sizeof 'a', sizeof "a");
return 0;
}

What is the output and why are they different for 'a' and "a"?
What does you textbook say about this?

Nov 24 '07 #2
In article <fi**********@registered.motzarella.org>, santosh
<sa*********@gmail.comwrote on Saturday 24 Nov 2007 3:28 pm:
In article
<bf**********************************@s19g2000prg. googlegroups.com>,
da****@gmail.com <da****@gmail.comwrote on Saturday 24 Nov 2007 2:57
pm:
>what is the difference between a single character and a string
consisting only one character

Try this program:

#include <stdio.h>

int main(void) {
char c0 = '0';
char c1[] = "0";

printf("Size of c0 is %u\nSize of c1 is %u\n", sizeof c0, sizeof
c1); return 0;
}

What is the output and why are the sizes for 'c0' and 'c1' different?
What does your C textbook say?

And try this one too:

#include <stdio.h>

int main(void) {
printf("Size of 'a' is %u\nSize of \"a\" is %u\n",
sizeof 'a', sizeof "a");
return 0;
}

What is the output and why are they different for 'a' and "a"?
What does you textbook say about this?
Note that this second example could confuse you if you happen to compile
on systems where the type int is two bytes.

It's still worthwhile to consult your prescribed textbook and do a bit
of thinking on your own rather than ask for instant answers in
newsgroups.

Nov 24 '07 #3
da****@gmail.com wrote:
what is the difference between a single character and a string
consisting only one character
One's a single character, and the other is a sequence containing
a single character, implemented as a pointer to a sequence of
characters the second of which is a terminating nul character and
the first is the character in the string.

It's like the difference between an apple and a paper bag containing
an apple: the bag is not an apple, even though you can get an apple
out of it, or replace the apple with an orange. (Since the string
bag can contain only one fruit character, you can't mix apples and
oranges [1].)

[1] In this bag. In bigger bags you can.

--
Perhaps Caffeine Now? Hedgehog
"A facility for quotation covers the absence of original thought." /Gaudy Night/

Nov 24 '07 #4
On Nov 24, 5:58 pm, santosh <santosh....@gmail.comwrote:
In article
<bffb8ed3-e648-424a-a49f-f68b7b1a9...@s19g2000prg.googlegroups.com>,
dat...@gmail.com <dat...@gmail.comwrote on Saturday 24 Nov 2007 2:57
pm:
what is the difference between a single character and a string
consisting only one character

Try this program:

#include <stdio.h>

int main(void) {
char c0 = '0';
char c1[] = "0";
This string "0" consists of two characters. The only string that
consists of a single char is "".
Nov 24 '07 #5
In article <a3**********************************@d4g2000prg.g ooglegroups.com>,
lovecreatesbea...@gmail.com <lo***************@gmail.comwrote:
>On Nov 24, 5:58 pm, santosh <santosh....@gmail.comwrote:
>In article
<bffb8ed3-e648-424a-a49f-f68b7b1a9...@s19g2000prg.googlegroups.com>,
dat...@gmail.com <dat...@gmail.comwrote on Saturday 24 Nov 2007 2:57
pm:
what is the difference between a single character and a string
consisting only one character

Try this program:

#include <stdio.h>

int main(void) {
char c0 = '0';
char c1[] = "0";

This string "0" consists of two characters. The only string that
consists of a single char is "".
strlen() and common sense say otherwise. You are confusing how big
something is with how much space it takes to store it. They are rarely
the same thing, and the later is usually greater than the former.

Nov 24 '07 #6
"da****@gmail.com" wrote:
>
what is the difference between a single character and a string
consisting only one character
The character contains exactly one char. The string contains two
chars, the char followed by '\0'. It the char is 'c', then you can
define the two cases with:

char c = 'c'; /* single char */
char *s = "c"; /* a string, non modifiable */
char m[] = "c"; /* a string, modifiable */

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 24 '07 #7
lovecreatesbea...@gmail.com wrote:
This string "0" consists of two characters.
The nul terminator isn't one of the characters "in" a
string.

--
Misplaced Hedgehog
Otherface: Jena RDF/Owl toolkit http://jena.sourceforge.net/

Nov 24 '07 #8
da****@gmail.com wrote:
what is the difference between a single character and a string
consisting only one character
You are posting too early in your knowledge quest. Read your book.

char ch = 'A';
char *ar = "A";

ch is the name of an object of type char which holds the value 'A'.

ar is the name of an object of type char* which holds the address of an
array of two char objects, 'A' and '\0'.

These two are exquisitely different things. Both are explained in your
book. Please read your C book.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 24 '07 #9
On Sat, 24 Nov 2007 17:31:43 +0000, Chris Dollin wrote:
lovecreatesbea...@gmail.com wrote:
>This string "0" consists of two characters.

The nul terminator isn't one of the characters "in" a string.
From a common sense perspective:
char a[] = "0";
and
char a[] = { '0', '\0' };
do exactly the same thing, and common sense says that '\0' is "in" a in
the second case, so it must also be "in" a in the first.

From a standards perspective:
A string is defined as "a contiguous sequence of characters terminated by
and including the first null character".
Nov 24 '07 #10
Chris Dollin wrote:
lovecreatesbea...@gmail.com wrote:
>This string "0" consists of two characters.

The nul terminator isn't one of the X-Mozilla-Status: 0009ng.
But it IS one of the characters in the char array holding the
string.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 25 '07 #11
On Sat, 24 Nov 2007 01:27:26 -0800 (PST), "da****@gmail.com"
<da****@gmail.comwrote:
>what is the difference between a single character and a string
consisting only one character
Since a string must be terminated with a '\0', the only possible
1-character string is "". If instead you meant a string whose length
is 1, then such a string obviously contains two characters.

A single character can contain any one of at least 256 possible
values.
Remove del for email
Nov 25 '07 #12
CBFalconer wrote:
Chris Dollin wrote:
>lovecreatesbea...@gmail.com wrote:
>>This string "0" consists of two characters.

The nul terminator isn't one of the X-Mozilla-Status: 0009ng.
Urm -- what happened there?
But it IS one of the characters in the char array holding the
string.
Oh, yes.
Elsethread $)CHarald van D )& k <tr*****@gmail.com(and
what happened /there/? Is my newsgarbler doing something
odd to names & content?) remarks

| From a standards perspective:
| A string is defined as "a contiguous sequence of characters
| terminated by and including the first null character".

which would make my position unsupported by the Standard's
terminology.

--
One-Hand Hedgehog
Notmuchhere: http://www.electrichedgehog.net/

Nov 25 '07 #13
In article <WM********************@fe1.news.blueyonder.co.uk> , Chris
Dollin <eh@electrichedgehog.netwrote on Sunday 25 Nov 2007 2:26 pm:
CBFalconer wrote:
>Chris Dollin wrote:
>>lovecreatesbea...@gmail.com wrote:

This string "0" consists of two characters.

The nul terminator isn't one of the X-Mozilla-Status: 0009ng.

Urm -- what happened there?
>But it IS one of the characters in the char array holding the
string.

Oh, yes.
Elsethread $)CHarald van D )& k <tr*****@gmail.com(and
what happened /there/? Is my newsgarbler doing something
odd to names & content?) remarks
No. His name appears mangled on my newsserver/newsreader too. I suspect
that he is using an encoding not supported by some software in the
Usenet hierarchy.

It was fine when Harald started posting to this group, but for a few
months now, his name has not been displayed properly.
| From a standards perspective:
| A string is defined as "a contiguous sequence of characters
| terminated by and including the first null character".

which would make my position unsupported by the Standard's
terminology.
Yes. So my first post contains errors. Hopefully the OP would have read
far enough into the thread to note the corrections.

Nov 25 '07 #14
On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
In article <WM********************@fe1.news.blueyonder.co.uk> , Chris
Dollin <eh@electrichedgehog.netwrote on Sunday 25 Nov 2007 2:26 pm:
>Oh, yes.
Elsethread $)CHarald van D )& k <tr*****@gmail.com(and what
happened /there/? Is my newsgarbler doing something odd to names &
content?) remarks

No. His name appears mangled on my newsserver/newsreader too. I suspect
that he is using an encoding not supported by some software in the
Usenet hierarchy.

It was fine when Harald started posting to this group, but for a few
months now, his name has not been displayed properly.
Apparently KNode encoded my name in utf-8, but Pan encodes it in iso-2022-
kr. I'll check if there's an option to change that.
Nov 25 '07 #15
On Sun, 25 Nov 2007 12:32:13 +0000, Harald van Dijk wrote:
On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
>It was fine when Harald started posting to this group, but for a few
months now, his name has not been displayed properly.

Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.
Does it display better like this?
Nov 25 '07 #16
In article <fi**********@news4.zwoll1.ov.home.nl>, Harald van D?k
<tr*****@gmail.comwrote on Sunday 25 Nov 2007 6:32 pm:
On Sun, 25 Nov 2007 12:32:13 +0000, Harald van D?k wrote:
>On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
>>It was fine when Harald started posting to this group, but for a few
months now, his name has not been displayed properly.

Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.

Does it display better like this?
Yes. It is now displayed correctly.

Nov 25 '07 #17
Harald van Dijk wrote:
On Sun, 25 Nov 2007 12:32:13 +0000, Harald van Dijk wrote:
>On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
>>It was fine when Harald started posting to this group, but for a few
months now, his name has not been displayed properly.
Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.

Does it display better like this?
Yes.
Nov 25 '07 #18
Harald van D?k said:
On Sun, 25 Nov 2007 12:32:13 +0000, Harald van D?k wrote:
>On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
>>It was fine when Harald started posting to this group, but for a few
months now, his name has not been displayed properly.

Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.

Does it display better like this?
Yes. But you're still going to have problems with the i-j ligature (or
diphthong, or whatever the proper name is).

--
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
Nov 25 '07 #19
In article <fi**********@registered.motzarella.org>, santosh
<sa*********@gmail.comwrote on Sunday 25 Nov 2007 5:28 pm:
In article <fi**********@news4.zwoll1.ov.home.nl>, Harald van D?k
<tr*****@gmail.comwrote on Sunday 25 Nov 2007 6:32 pm:
>On Sun, 25 Nov 2007 12:32:13 +0000, Harald van D?k wrote:
>>On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
It was fine when Harald started posting to this group, but for a
few months now, his name has not been displayed properly.

Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.

Does it display better like this?

Yes. It is now displayed correctly.
Oops. It was correct when I received and replied to it, but not when I
read it back, as you can see.

Nov 25 '07 #20
Harald van Dijk <tr*****@gmail.comwrites:
On Sun, 25 Nov 2007 12:32:13 +0000, Harald van Dijk wrote:
<snip>
>Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.

Does it display better like this?
Just a data point. Gnus displays both.

--
Ben.
Nov 25 '07 #21
On Sat, 24 Nov 2007 15:28:32 +0530, santosh <sa*********@gmail.com>
wrote:
>In article
<bf**********************************@s19g2000prg .googlegroups.com>,
da****@gmail.com <da****@gmail.comwrote on Saturday 24 Nov 2007 2:57
pm:
>what is the difference between a single character and a string
consisting only one character

Try this program:

#include <stdio.h>

int main(void) {
char c0 = '0';
char c1[] = "0";

printf("Size of c0 is %u\nSize of c1 is %u\n", sizeof c0, sizeof c1);
Since size_t could be different than unsigned int, you should probably
the cast the second and third arguments to match the format
specification.
return 0;
}

Remove del for email
Nov 25 '07 #22
Harald van D?k wrote:
Harald van Dijk wrote:
>santosh wrote:
>>It was fine when Harald started posting to this group, but for a
few months now, his name has not been displayed properly.

Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.

Does it display better like this?
Yes, except for the middle character in the name "D?k". That is
still a bind for any return e-mail addresses.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 25 '07 #23
On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),
ga*****@xmission.xmission.com (Kenny McCormack) wrote:
>In article <a3**********************************@d4g2000prg.g ooglegroups.com>,
lovecreatesbea...@gmail.com <lo***************@gmail.comwrote:
snip
>>This string "0" consists of two characters. The only string that
consists of a single char is "".

strlen() and common sense say otherwise. You are confusing how big
something is with how much space it takes to store it. They are rarely
the same thing, and the later is usually greater than the former.
And you are refusing to accept the definition in the standard. From
para 7.1.1-1: "A string is a contiguous sequence of characters
terminated by and including the first null character."
Remove del for email
Nov 25 '07 #24
Harald van Dijk wrote:
On Sun, 25 Nov 2007 12:32:13 +0000, Harald van Dijk wrote:
>On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
>>It was fine when Harald started posting to this group, but for a few
months now, his name has not been displayed properly.
Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.

Does it display better like this?
It seems Thunderbird also copes well, including not munging the
attribution line.
Nov 25 '07 #25
Barry Schwarz <sc******@doezl.netwrites:
On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),
ga*****@xmission.xmission.com (Kenny McCormack) wrote:
>>In article <a3**********************************@d4g2000prg.g ooglegroups.com>,
lovecreatesbea...@gmail.com <lo***************@gmail.comwrote:

snip
>>>This string "0" consists of two characters. The only string that
consists of a single char is "".

strlen() and common sense say otherwise. You are confusing how big
something is with how much space it takes to store it. They are rarely
the same thing, and the later is usually greater than the former.

And you are refusing to accept the definition in the standard. From
para 7.1.1-1: "A string is a contiguous sequence of characters
terminated by and including the first null character."
And you are refusing to understand what KM said. There is a difference
between the length of a string and the space needed to store it. As is
clear from this thread and has been true since the day C was invented.

Length is analogous to "how many character do you display in the real
world" whereas "size" is "how much storage space do you need".
>

Remove del for email
Nov 25 '07 #26
santosh wrote:
In article <fi**********@registered.motzarella.org>, santosh
<sa*********@gmail.comwrote on Sunday 25 Nov 2007 5:28 pm:
In article <fi**********@news4.zwoll1.ov.home.nl>, Harald van D?k
<tr*****@gmail.comwrote on Sunday 25 Nov 2007 6:32 pm:
\
Does it display better like this?
Yes. It is now displayed correctly.

Oops. It was correct when I received and replied to it, but not when I
read it back, as you can see.

Your newsreader switched the char set from UTF-8 (the original) to
Western European.

Brian
Nov 25 '07 #27
Richard wrote:
Barry Schwarz <sc******@doezl.netwrites:
>On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),
ga*****@xmission.xmission.com (Kenny McCormack) wrote:
>>In article <a3**********************************@d4g2000prg.g ooglegroups.com>,
lovecreatesbea...@gmail.com <lo***************@gmail.comwrote:
snip
>>>This string "0" consists of two characters. The only string that
consists of a single char is "".
strlen() and common sense say otherwise. You are confusing how big
something is with how much space it takes to store it. They are rarely
the same thing, and the later is usually greater than the former.
And you are refusing to accept the definition in the standard. From
para 7.1.1-1: "A string is a contiguous sequence of characters
terminated by and including the first null character."

And you are refusing to understand what KM said. There is a difference
between the length of a string and the space needed to store it. As is
clear from this thread and has been true since the day C was invented.
And you are refusing to look at what Kenny said in context. Kenny
claimed that the statement
>>>This string "0" consists of two characters. The only string that
consists of a single char is "".
was wrong. Kenny was incorrect, totally and absolutely, by definition.
Kenny introduced the ideas of "how big something is" and "how much space
it takes" which aren't relevant to the statement he was supposedly
correcting. A string consists of a sequence of characters up to and
including the first null character, and has done since the day C was
invented.
Length is analogous to "how many character do you display in the real
world" whereas "size" is "how much storage space do you need".
If that's how you choose to define them, that's fine. It's not relevant
to the question in hand though.
Nov 25 '07 #28
"J. J. Farrell" <jj*@bcs.org.ukwrites:
Richard wrote:
>Barry Schwarz <sc******@doezl.netwrites:
>>On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),
ga*****@xmission.xmission.com (Kenny McCormack) wrote:

In article <a3**********************************@d4g2000prg.g ooglegroups.com>,
lovecreatesbea...@gmail.com <lo***************@gmail.comwrote:
snip

This string "0" consists of two characters. The only string that
consists of a single char is "".
strlen() and common sense say otherwise. You are confusing how big
something is with how much space it takes to store it. They are rarely
the same thing, and the later is usually greater than the former.
And you are refusing to accept the definition in the standard. From
para 7.1.1-1: "A string is a contiguous sequence of characters
terminated by and including the first null character."

And you are refusing to understand what KM said. There is a difference
between the length of a string and the space needed to store it. As is
clear from this thread and has been true since the day C was invented.

And you are refusing to look at what Kenny said in context. Kenny
claimed that the statement
>>>>This string "0" consists of two characters. The only string that
consists of a single char is "".

was wrong. Kenny was incorrect, totally and absolutely, by
Not in the context of what he said which was that "strlen" and "common
sense" say otherwise. Not the standard.

strlen and "common sense" say that the string length of "0" is 1. The
size is 2. That is a different thing.

But we know what me mean. No point in getting in tedious language wars
here.
definition. Kenny introduced the ideas of "how big something is" and
"how much space it takes" which aren't relevant to the statement he
was supposedly correcting. A string consists of a sequence of
characters up to and including the first null character, and has done
since the day C was invented.
>Length is analogous to "how many character do you display in the real
world" whereas "size" is "how much storage space do you need".

If that's how you choose to define them, that's fine. It's not
relevant to the question in hand though.
Actually its totally relevant since it defines the difference between
the "length" and the "size" which were the pertinent points here.

Nov 25 '07 #29
Richard wrote:
"J. J. Farrell" <jj*@bcs.org.ukwrites:
>Richard wrote:
>>Barry Schwarz <sc******@doezl.netwrites:

On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),
ga*****@xmission.xmission.com (Kenny McCormack) wrote:

In article <a3**********************************@d4g2000prg.g ooglegroups.com>,
lovecreatesbea...@gmail.com <lo***************@gmail.comwrote:
snip

>This string "0" consists of two characters. The only string that
>consists of a single char is "".
strlen() and common sense say otherwise. You are confusing how big
something is with how much space it takes to store it. They are rarely
the same thing, and the later is usually greater than the former.
And you are refusing to accept the definition in the standard. From
para 7.1.1-1: "A string is a contiguous sequence of characters
terminated by and including the first null character."
And you are refusing to understand what KM said. There is a difference
between the length of a string and the space needed to store it. As is
clear from this thread and has been true since the day C was invented.
And you are refusing to look at what Kenny said in context. Kenny
claimed that the statement
>>>>>This string "0" consists of two characters. The only string that
>consists of a single char is "".
was wrong. Kenny was incorrect, totally and absolutely, by

Not in the context of what he said which was that "strlen" and "common
sense" say otherwise. Not the standard.

strlen and "common sense" say that the string length of "0" is 1. The
size is 2. That is a different thing.

But we know what me mean. No point in getting in tedious language wars
here.
Agreed.
>definition. Kenny introduced the ideas of "how big something is" and
"how much space it takes" which aren't relevant to the statement he
was supposedly correcting. A string consists of a sequence of
characters up to and including the first null character, and has done
since the day C was invented.
>>Length is analogous to "how many character do you display in the real
world" whereas "size" is "how much storage space do you need".
If that's how you choose to define them, that's fine. It's not
relevant to the question in hand though.

Actually its totally relevant since it defines the difference between
the "length" and the "size" which were the pertinent points here.
The pertinent points here are whether or not the string "0" consists of
two chars, and whether or not the only string that consists of a single
char is "". Those two statements are true no matter how you define size
and length. The difference between size and length isn't relevant.
Nov 26 '07 #30
santosh wrote:
In article <fi**********@news4.zwoll1.ov.home.nl>, Harald van D?k
<tr*****@gmail.comwrote on Sunday 25 Nov 2007 6:32 pm:
>On Sun, 25 Nov 2007 12:32:13 +0000, Harald van D?k wrote:
>>On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
It was fine when Harald started posting to this group, but for a few
months now, his name has not been displayed properly.

Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.

Does it display better like this?

Yes. It is now displayed correctly.
Here too.

--
Echo Hedgehog
Nit-picking is best done among friends.

Nov 26 '07 #31
On Mon, 26 Nov 2007 07:48:23 +0000, Chris Dollin wrote:
santosh wrote:
>In article <fi**********@news4.zwoll1.ov.home.nl>, Harald van D?k
<tr*****@gmail.comwrote on Sunday 25 Nov 2007 6:32 pm:
>>On Sun, 25 Nov 2007 12:32:13 +0000, Harald van D?k wrote:
On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
It was fine when Harald started posting to this group, but for a few
months now, his name has not been displayed properly.

Apparently KNode encoded my name in utf-8, but Pan encodes it in
iso-2022-kr. I'll check if there's an option to change that.

Does it display better like this?

Yes. It is now displayed correctly.

Here too.
Thanks all for the information.
Nov 26 '07 #32
Richard wrote:
>
Barry Schwarz <sc******@doezl.netwrites:
On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),
ga*****@xmission.xmission.com (Kenny McCormack) wrote:
>In article <a3**********************************@d4g2000prg.g ooglegroups.com>,
lovecreatesbea...@gmail.com <lo***************@gmail.comwrote:
snip
>>This string "0" consists of two characters. The only string that
consists of a single char is "".

strlen() and common sense say otherwise. You are confusing how big
something is with how much space it takes to store it.
They are rarely
the same thing, and the later is usually greater than the former.
And you are refusing to accept the definition in the standard. From
para 7.1.1-1: "A string is a contiguous sequence of characters
terminated by and including the first null character."

And you are refusing to understand what KM said. There is a difference
between the length of a string and the space needed to store it. As is
clear from this thread and has been true since the day C was invented.

Length is analogous to "how many character do you display in the real
world" whereas "size" is "how much storage space do you need".
A null byte in an object, is a string.
A null byte consists of one character.

--
pete
Nov 27 '07 #33
On Sun, 25 Nov 2007 19:31:12 +0100, Richard <rg****@gmail.comwrote:
>Barry Schwarz <sc******@doezl.netwrites:
>On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),
ga*****@xmission.xmission.com (Kenny McCormack) wrote:
>>>In article <a3**********************************@d4g2000prg.g ooglegroups.com>,
lovecreatesbea...@gmail.com <lo***************@gmail.comwrote:

snip
>>>>This string "0" consists of two characters. The only string that
consists of a single char is "".

strlen() and common sense say otherwise. You are confusing how big
something is with how much space it takes to store it. They are rarely
the same thing, and the later is usually greater than the former.

And you are refusing to accept the definition in the standard. From
para 7.1.1-1: "A string is a contiguous sequence of characters
terminated by and including the first null character."

And you are refusing to understand what KM said. There is a difference
between the length of a string and the space needed to store it. As is
clear from this thread and has been true since the day C was invented.
The original message that started this thread did not mention length.
It simply asked "what is the difference between a single character and
a string consisting only one character". In this context,
lovecreatesbeauty's answer is exactly correct. There is only one
possible string consisting of a single character. KMcC chose to
debate the point. He is wrong.
>
Length is analogous to "how many character do you display in the real
world" whereas "size" is "how much storage space do you need".
All possibly true but not related to the issue under discussion. If
the OP had asked what is the difference between a single character a
string of length one, the thread would have gone in a completely
different direction.
Remove del for email
Nov 27 '07 #34
Chris Dollin wrote:
The nul terminator isn't one of the characters "in" a string.
That's just completely wrong.
The standard says that the null byte is part of the string.
The number of participants in this thread
who know what a string is, is dissappointingly small.

--
pete
Nov 27 '07 #35
pete wrote:
Chris Dollin wrote:
>The nul terminator isn't one of the characters "in" a string.

That's just completely wrong.
No ...
The standard says that the null byte is part of the string.
.... yes. (Did you miss my earlier post?)
The number of participants in this thread
who know what a string is, is dissappointingly small.
It's not to do with what a string "is". It's to do with the meaning
of the term "character in a string". The blindingly obvious [1]
meaning of "the string S contains the character C" and the meaning
implied by the Standard are not the same; this is an interesting
fact, but it doesn't make the obvious meaning "completely wrong".

[1] To me; viz, C is in S if C == S[i] for some i in 0 .. strlen(S) - 1.

--
Chris "fencepost" Dollin

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Nov 27 '07 #36
pete wrote:
Chris Dollin wrote:
>The nul terminator isn't one of the characters "in" a string.

That's just completely wrong.
The standard says that the null byte is part of the string.
The number of participants in this thread
who know what a string is, is dissappointingly small.
char str[] = "Hello";
The sizeof str is 6 while strlen(str) is 5.
While the nul is of type char it's not really a character, is it?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 28 '07 #37
In article <tt******************************@comcast.com>,
Joe Wright <jo********@comcast.netwrote:
>pete wrote:
>Chris Dollin wrote:
>>The nul terminator isn't one of the characters "in" a string.
>That's just completely wrong.
The standard says that the null byte is part of the string.
The number of participants in this thread
who know what a string is, is dissappointingly small.
>char str[] = "Hello";
The sizeof str is 6 while strlen(str) is 5.
While the nul is of type char it's not really a character, is it?
Yes, it really is a character.

C89 2.2.1 Character Sets

A byte with all bits set to 0, called the null character, shall
exist in the basic execution character set; it is used to terminate
a character string literal.
--
"I was very young in those days, but I was also rather dim."
-- Christopher Priest
Nov 28 '07 #38
Chris Dollin wrote:
The blindingly obvious [1]
meaning of "the string S contains the character C" and the meaning
implied by the Standard are not the same;
I prefer to use the C standard's definitions
for terms when discussing C in the C newsgroup.

--
pete
Nov 28 '07 #39
pete wrote:
Chris Dollin wrote:
>The blindingly obvious [1]
meaning of "the string S contains the character C" and the meaning
implied by the Standard are not the same;

I prefer to use the C standard's definitions
for terms when discussing C in the C newsgroup.
And hence it is useful to know that "The blindingly obvious [1]
meaning of "the string S contains the character C" and the meaning
implied by the Standard are not the same."

--
Chris "certainly it's useful to /me/" Dollin

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Nov 28 '07 #40
On Nov 24, 3:27 am, "dat...@gmail.com" <dat...@gmail.comwrote:
what is the difference between a single character and a string
consisting only one character
39 posts so far (as displayed here), and no answer. Philosophy is fun!

Yevgen
Nov 28 '07 #41
ym******@gmail.com wrote:
On Nov 24, 3:27 am, "dat...@gmail.com" <dat...@gmail.comwrote:
>what is the difference between a single character and a string
consisting only one character

39 posts so far (as displayed here), and no answer. Philosophy is fun!
Huh? There *have* been answers, just not ones handed out on a plate.

Nov 28 '07 #42
ym******@gmail.com wrote:
On Nov 24, 3:27 am, "dat...@gmail.com" <dat...@gmail.comwrote:
>what is the difference between a single character and a string
consisting only one character

39 posts so far (as displayed here), and no answer.
Clean your glasses. Or your NNTP connection.

--
Chris "isopropyl" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Nov 28 '07 #43
ym******@gmail.com wrote:
On Nov 28, 9:07 am, santosh <santosh....@gmail.comwrote:
>ymunt...@gmail.com wrote:
On Nov 24, 3:27 am, "dat...@gmail.com" <dat...@gmail.comwrote:
what is the difference between a single character and a string
consisting only one character
39 posts so far (as displayed here), and no answer. Philosophy is
fun!

Huh? There *have* been answers, just not ones handed out on a plate.

Well, for instance yours wasn't an answer to the original question.
But I could have missed one, I guess.
At a glance you seem to have missed at least four perfectly good
answers. I agree that mine wasn't one of them.

As for the sub-thread following the post by "lovecreatesbeauty", the OP
can easily ignore that if he is not interested in legalistic minutiae.

<snip>

Nov 28 '07 #44
On Nov 28, 9:19 am, Chris Dollin <chris.dol...@hp.comwrote:
ymunt...@gmail.com wrote:
On Nov 24, 3:27 am, "dat...@gmail.com" <dat...@gmail.comwrote:
what is the difference between a single character and a string
consisting only one character
39 posts so far (as displayed here), and no answer.

Clean your glasses.
I actually did.
Or your NNTP connection.
This I can't do unfortunately. Could you quote the answer?

Yevgen "comp.lang.c is fun as usual" Muntyan
Nov 28 '07 #45
santosh <sa*********@gmail.comwrites:
ym******@gmail.com wrote:
>On Nov 24, 3:27 am, "dat...@gmail.com" <dat...@gmail.comwrote:
>>what is the difference between a single character and a string
consisting only one character

39 posts so far (as displayed here), and no answer. Philosophy is fun!

Huh? There *have* been answers, just not ones handed out on a plate.
How do you answer questions then? In code?
Nov 28 '07 #46
ym******@gmail.com wrote:
On Nov 28, 9:19 am, Chris Dollin <chris.dol...@hp.comwrote:
>ymunt...@gmail.com wrote:
>>On Nov 24, 3:27 am, "dat...@gmail.com" <dat...@gmail.comwrote:
what is the difference between a single character and a string
consisting only one character
39 posts so far (as displayed here), and no answer.
Clean your glasses.

I actually did.
>Or your NNTP connection.

This I can't do unfortunately. Could you quote the answer?
No. This group helps those who help themselves. I feel that Chris
Dollin's, CBFalconer's, Joe Wright's, and Barry Schwarz's responses
provide all the necessary information to answer the OP.
Nov 28 '07 #47
ym******@gmail.com wrote:
On Nov 24, 3:27 am, "dat...@gmail.com" <dat...@gmail.comwrote:
>what is the difference between a single character and a string
consisting only one character

39 posts so far (as displayed here), and no answer. Philosophy is fun!
I'd get a better news server. There were three or four thorough answers
posted three or four days ago, along with others which would help the OP
work it out for himself.
Nov 28 '07 #48
On Nov 28, 11:13 am, Philip Potter <p...@doc.ic.ac.ukwrote:
ymunt...@gmail.com wrote:
On Nov 28, 9:19 am, Chris Dollin <chris.dol...@hp.comwrote:
ymunt...@gmail.com wrote:
On Nov 24, 3:27 am, "dat...@gmail.com" <dat...@gmail.comwrote:
what is the difference between a single character and a string
consisting only one character
39 posts so far (as displayed here), and no answer.
Clean your glasses.
I actually did.
Or your NNTP connection.
This I can't do unfortunately. Could you quote the answer?

No. This group helps those who help themselves. I feel that Chris
Dollin's, CBFalconer's, Joe Wright's, and Barry Schwarz's responses
provide all the necessary information to answer the OP.
You mean responses talking about strings of
length 1? Those are not strings "consisting
only one character". Or perhaps stuff about
whether nul character is a character?

Anyway, there wasn't an answer, do I understand
you correctly? Because I agree there was more
than enough information. I just hoped someone
could formulate the difference between a nul
character and the string it makes. I seriously
tried and didn't succeed, went into metaphysics.
Oh well.

Best regards,
Yevgen
Nov 28 '07 #49
On Tue, 27 Nov 2007 16:14:55 +0000, Chris Dollin <ch**********@hp.com>
wrote:
>pete wrote:
>Chris Dollin wrote:
>>The nul terminator isn't one of the characters "in" a string.

That's just completely wrong.

No ...
>The standard says that the null byte is part of the string.

... yes. (Did you miss my earlier post?)
>The number of participants in this thread
who know what a string is, is dissappointingly small.

It's not to do with what a string "is". It's to do with the meaning
of the term "character in a string". The blindingly obvious [1]
But it has everything to do with what a string is. The orignal poster
asked "what is the difference between a single character and
a string consisting only one character". Since the standard says the
terminating null is part of the string, can you write any string other
than "" consisting of a single character?

>meaning of "the string S contains the character C" and the meaning
implied by the Standard are not the same; this is an interesting
fact, but it doesn't make the obvious meaning "completely wrong".

[1] To me; viz, C is in S if C == S[i] for some i in 0 .. strlen(S) - 1.
Since by definition the standard cannot be wrong and since your
meaning precludes the '\0' from being part of the string as the
standard says it is, what part of completely wrong doesn't apply?
Remove del for email
Nov 29 '07 #50

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

Similar topics

5
by: Pavils Jurjans | last post by:
Hello, Here's an excerpt from msdn online documentation: An index is the position of a Char, not a Unicode character, in a String. An index is a zero-based, nonnegative number starting from...
3
by: John Salerno | last post by:
This is an example in the book I'm reading: string fullName = " Edward C Koop "; fullName = fullName.Trim(); string names = fullName.Split(' '); string firstName = names; //...
33
by: Lalatendu Das | last post by:
Dear friends, I am getting a problem in the code while interacting with a nested Do-while loop It is skipping a scanf () function which it should not. I have written the whole code below. Please...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
23
by: Steven T. Hatton | last post by:
This is one of the first obstacles I encountered when getting started with C++. I found that everybody had their own idea of what a string is. There was std::string, QString, xercesc::XMLString,...
8
by: hu | last post by:
hi, everybody! I'm testing the fuction of strtok(). The environment is WinXP, VC++6.0. Program is simple, but mistake is confusing. First, the below code can get right outcome:"ello world, hello...
5
by: hn.ft.pris | last post by:
Hi: I'm a beginer of STL, and I'm wondering why none of below works: ######################################################################## .......... string str("string"); if ( str == "s" )...
21
by: softwindow | last post by:
#include "stdio.h" #include "malloc.h" struct student{ int age; char *nms; struct student *next; }; struct student *create(){ int ags=0,size=sizeof(struct student); char *nms=" ";
7
by: tempest | last post by:
Hi all. This is a rather long posting but I have some questions concerning the usage of character entities in XML documents and PCI security compliance. The company I work for is using a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.