|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
what is the difference between a single character and a string
consisting only one character |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
In article
<bffb8ed3-e648-424a-a49f-f68b7b1a9ee0@s19g2000prg.googlegroups.com>, dattts@gmail.com <dattts@gmail.com> wrote 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? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
In article <fi8ska$rev$1@registered.motzarella.org>, santosh
<santosh.k83@gmail.com> wrote on Saturday 24 Nov 2007 3:28 pm: > In article > <bffb8ed3-e648-424a-a49f-f68b7b1a9ee0@s19g2000prg.googlegroups.com>, > dattts@gmail.com <dattts@gmail.com> wrote 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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
dattts@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/ |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Nov 24, 5:58 pm, santosh <santosh....@gmail.com> wrote:
> In article > <bffb8ed3-e648-424a-a49f-f68b7b1a9...@s19g2000prg.googlegroups.com>, > dat...@gmail.com <dat...@gmail.com> wrote 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 "". |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
In article <a3f33b3f-bb91-4dff-b2ea-9c4f2b13d84a@d4g2000prg.googlegroups.com>,
lovecreatesbea...@gmail.com <lovecreatesbeauty@gmail.com> wrote: >On Nov 24, 5:58 pm, santosh <santosh....@gmail.com> wrote: >> In article >> <bffb8ed3-e648-424a-a49f-f68b7b1a9...@s19g2000prg.googlegroups.com>, >> dat...@gmail.com <dat...@gmail.com> wrote 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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
"dattts@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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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/ |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
dattts@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 --- |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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". |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
On Sat, 24 Nov 2007 01:27:26 -0800 (PST), "dattts@gmail.com"
<dattts@gmail.com> wrote: >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 |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
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 <truedfx@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/ |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
In article <WMa2j.152625$vI1.47245@fe1.news.blueyonder.co.uk> , Chris
Dollin <eh@electrichedgehog.net> wrote 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 <truedfx@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. |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
In article <fibrpm$mco$2@news4.zwoll1.ov.home.nl>, Harald van D?k
<truedfx@gmail.com> wrote 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. |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#17 |
|
Messages: n/a
Hébergeur: |
On Sun, 25 Nov 2007 14:47:18 +0530, santosh wrote:
> In article <WMa2j.152625$vI1.47245@fe1.news.blueyonder.co.uk> , Chris > Dollin <eh@electrichedgehog.net> wrote on Sunday 25 Nov 2007 2:26 pm: >> Oh, yes. >> Elsethread $)CHarald van D )& k <truedfx@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. |
|
|
|
#18 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#19 |
|
Messages: n/a
Hébergeur: |
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? |
|
|
|
#20 |
|
Messages: n/a
Hébergeur: |
In article <fibo1c$sk3$1@registered.motzarella.org>, santosh
<santosh.k83@gmail.com> wrote on Sunday 25 Nov 2007 5:28 pm: > In article <fibrpm$mco$2@news4.zwoll1.ov.home.nl>, Harald van D?k > <truedfx@gmail.com> wrote 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. |
|
|
|
#21 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#22 |
|
Messages: n/a
Hébergeur: |
Harald van Dijk <truedfx@gmail.com> writes:
> 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. |
|
|
|
#23 |
|
Messages: n/a
Hébergeur: |
On Sat, 24 Nov 2007 15:28:32 +0530, santosh <santosh.k83@gmail.com>
wrote: >In article ><bffb8ed3-e648-424a-a49f-f68b7b1a9ee0@s19g2000prg.googlegroups.com>, >dattts@gmail.com <dattts@gmail.com> wrote 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 |
|
|
|
#24 |
|
Messages: n/a
Hébergeur: |
On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),
gazelle@xmission.xmission.com (Kenny McCormack) wrote: >In article <a3f33b3f-bb91-4dff-b2ea-9c4f2b13d84a@d4g2000prg.googlegroups.com>, >lovecreatesbea...@gmail.com <lovecreatesbeauty@gmail.com> wrote: 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 |
|
|
|
#25 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|