Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > about string and character

Reply
Thread Tools

about string and character

 
 
Philip Potter
Guest
Posts: n/a
 
      11-28-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Nov 28, 9:19 am, Chris Dollin <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>> On Nov 24, 3:27 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>>>> 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.
 
Reply With Quote
 
 
 
 
J. J. Farrell
Guest
Posts: n/a
 
      11-28-2007
(E-Mail Removed) wrote:
> On Nov 24, 3:27 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>> 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.
 
Reply With Quote
 
 
 
 
J. J. Farrell
Guest
Posts: n/a
 
      11-28-2007
Philip Potter wrote:
> (E-Mail Removed) wrote:
>> On Nov 28, 9:21 am, Chris Dollin <(E-Mail Removed)> wrote:
>>> (E-Mail Removed) wrote:
>>>> On Nov 28, 9:07 am, santosh <(E-Mail Removed)> wrote:
>>>>> (E-Mail Removed) wrote:
>>>>>> On Nov 24, 3:27 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>>>>>>> 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.
>>>> char a = 0;
>>>> The byte occupied by this object constitutes a one-character string,
>>>> you know.
>>> It does not. (Not in C, it doesn't.)

>>
>> Yes it does. It constitutes a (one-element) contiguous sequence
>> of characters terminated by and including the first null character.


Yes, a string of length zero.

> A sequence of characters has type char[].


Chapter and Verse, please. As far as I can see, the Standard uses
"sequence" in a normal English sense, with the extension of allowing a
sequence to be empty. I can't see any requirement that a sequence of
characters have type char[].

> Your variable 'a' has type
> char. Therefore, a is not a sequence of one character. If you had
> instead said:
>
> char a[1] = {0};
>
> then your statement would have been correct.
>
> Other properties of a sequence which your variable 'a' lacks:
>
> * Sequences can be subscripted: a[i]


Arrays can be subscripted. There is no 'sequence' type in C.

> * Sequences decay to a pointer when, among other things, used as a
> function parameter - f(a) should pass a 'char *' to f()


Again, true of arrays but not of sequences.
 
Reply With Quote
 
ymuntyan@gmail.com
Guest
Posts: n/a
 
      11-28-2007
On Nov 28, 11:13 am, Philip Potter <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > On Nov 28, 9:19 am, Chris Dollin <(E-Mail Removed)> wrote:
> >> (E-Mail Removed) wrote:
> >>> On Nov 24, 3:27 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> >>>> 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
 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      11-29-2007
On Tue, 27 Nov 2007 16:14:55 +0000, Chris Dollin <(E-Mail Removed)>
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
 
Reply With Quote
 
karthikbalaguru
Guest
Posts: n/a
 
      11-29-2007
On Nov 24, 2:58 pm, santosh <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
> (E-Mail Removed) <(E-Mail Removed)> 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?


Nice.
Another interesting way of answering

Karthik Balaguru
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      11-29-2007
Chris Dollin <(E-Mail Removed)> writes:
> (E-Mail Removed) wrote:
>> On Nov 28, 9:07 am, santosh <(E-Mail Removed)> wrote:
>>> (E-Mail Removed) wrote:
>>> > On Nov 24, 3:27 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>>> >> 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.
>>
>> char a = 0;
>>
>> The byte occupied by this object constitutes a one-character string,
>> you know.

>
> It does not. (Not in C, it doesn't.)

[...]

I believe it does.

Consider this:

#include <stdio.h>
#include <string.h>
int main(void)
{
char a = 0;
printf("strlen(&a) = %d\n", (int)strlen(&a));
return 0;
}

A single object of the char can be treated as an array of one char.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      11-29-2007
Keith Thompson wrote:

> Chris Dollin <(E-Mail Removed)> writes:
>> (E-Mail Removed) wrote:
>>> On Nov 28, 9:07 am, santosh <(E-Mail Removed)> wrote:
>>>> (E-Mail Removed) wrote:
>>>> > On Nov 24, 3:27 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>>>> >> 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.
>>>
>>> char a = 0;
>>>
>>> The byte occupied by this object constitutes a one-character string,
>>> you know.

>>
>> It does not. (Not in C, it doesn't.)

> [...]
>
> I believe it does.
>
> Consider this:
>
> #include <stdio.h>
> #include <string.h>
> int main(void)
> {
> char a = 0;
> printf("strlen(&a) = %d\n", (int)strlen(&a));
> return 0;
> }
>
> A single object of the char can be treated as an array of one char.


Duh ... this time, the `= 0;` made it along the optic nerve to the
brain.

Point to Keith. I'm fortunate that I can't boil my head, which would
otherwise be the appropriate response.

--
Chris "head.size > pan.size" Dollin

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

 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      11-29-2007
Barry Schwarz wrote:

>>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?


"Completely".

--
Far-Fetched Hedgehog
The "good old days" used to be much better.

 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      11-30-2007
On Wed, 28 Nov 2007 07:10:58 -0800 (PST), (E-Mail Removed) wrote:

>On Nov 28, 9:07 am, santosh <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>> > On Nov 24, 3:27 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>> >> 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.
>
>char a = 0;
>
>The byte occupied by this object constitutes a one-character string,
>you know.
>Looking forward for amusing explanations of how a sequence of one
>element is
>different from one element


Then why don't you just code
char a = "";
and see what your compiler has to say about it?

Probably because you think you know this and are just trolling.

Here are four bytes in memory on an 8-byte boundary: 0x20414200.
Do they represent a string or part of one; four individual char; 2
short; 1 short; 2 int; 1 int; if either type of int are the
magnitude(s) large, medium, or small; 1 long; or one float? It's the
same four bytes; how could they possibly mean different things?

Try
char x[5];
void *p1 = x; /*(1)*/
void *p2 = &x; /*(2)*/

p1 is obviously equal to p2. Since equality is transitive, how can
the right hand expression of (1) possibly be different than the right
hand expression of (2)?


Remove del for email
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert string with control character in caret notation to realcontrol character string. Bart Vandewoestyne C Programming 8 09-25-2012 12:41 PM
FAQ 4.31 How can I split a [character] delimited string except when inside [character]? PerlFAQ Server Perl Misc 0 01-25-2011 05:00 AM
How can I replace all occurrences of a character with another character in std string? herman C++ 5 08-30-2007 09:05 AM
8 bit character string to 16 bit character string Brand Bogard C Programming 8 05-28-2006 05:05 PM
getting the character code of a character in a string Velvet ASP .Net 9 01-19-2006 09:27 PM



Advertisments