PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > about string and character
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
about string and character

Réponse
 
LinkBack Outils de la discussion
Vieux 24/11/2007, 09h27   #1
dattts@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut about string and character

what is the difference between a single character and a string
consisting only one character
  Réponse avec citation
Vieux 24/11/2007, 09h58   #2
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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?

  Réponse avec citation
Vieux 24/11/2007, 10h04   #3
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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.

  Réponse avec citation
Vieux 24/11/2007, 10h40   #4
Chris Dollin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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/

  Réponse avec citation
Vieux 24/11/2007, 13h54   #5
lovecreatesbea...@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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 "".
  Réponse avec citation
Vieux 24/11/2007, 15h56   #6
Kenny McCormack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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.

  Réponse avec citation
Vieux 24/11/2007, 16h07   #7
CBFalconer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

"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

  Réponse avec citation
Vieux 24/11/2007, 17h31   #8
Chris Dollin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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/

  Réponse avec citation
Vieux 24/11/2007, 17h43   #9
Joe Wright
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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 ---
  Réponse avec citation
Vieux 24/11/2007, 19h26   #10
$)CHarald van D)&k
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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".
  Réponse avec citation
Vieux 24/11/2007, 23h54   #11
CBFalconer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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

  Réponse avec citation
Vieux 25/11/2007, 06h12   #12
Barry Schwarz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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
  Réponse avec citation
Vieux 25/11/2007, 08h56   #13
Chris Dollin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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/

  Réponse avec citation
Vieux 25/11/2007, 09h17   #14
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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.

  Réponse avec citation
Vieux 25/11/2007, 11h58   #15
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: about string and character

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.

  Réponse avec citation
Vieux 25/11/2007, 12h24   #16
James Kuyper
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: about string and character

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.
  Réponse avec citation
Vieux 25/11/2007, 12h32   #17
$)CHarald van D)&k
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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.
  Réponse avec citation
Vieux 25/11/2007, 12h56   #18
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: about string and character

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
  Réponse avec citation
Vieux 25/11/2007, 13h02   #19
Harald van Dijk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut [OT] Re: about string and character

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?
  Réponse avec citation
Vieux 25/11/2007, 13h28   #20
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: about string and character

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.

  Réponse avec citation
Vieux 25/11/2007, 16h36   #21
CBFalconer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: about string and character

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

  Réponse avec citation
Vieux 25/11/2007, 16h57   #22
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: about string and character

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.
  Réponse avec citation
Vieux 25/11/2007, 17h18   #23
Barry Schwarz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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
  Réponse avec citation
Vieux 25/11/2007, 17h28   #24
Barry Schwarz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: about string and character

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
  Réponse avec citation
Vieux 25/11/2007, 17h31   #25
Philip Potter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: about string and character

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h38.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,46271 seconds with 33 queries