about string and character

C

CBFalconer

Harald said:
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.
 
B

Barry Schwarz

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
 
B

Barry Schwarz

On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),
snip


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

Richard

Barry Schwarz said:
On Sat, 24 Nov 2007 15:56:07 +0000 (UTC),


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".
 
D

Default User

santosh said:
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
 
J

J. J. Farrell

Richard said:
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

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.
 
R

Richard

J. J. Farrell said:
And you are refusing to look at what Kenny said in context. Kenny
claimed that the statement


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.


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.
 
J

J. J. Farrell

Richard said:
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.


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.
 
P

pete

Richard said:
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.
 
B

Barry Schwarz

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
 
P

pete

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.
 
C

Chris Dollin

pete said:
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 for some i in 0 .. strlen(S) - 1.
 
J

Joe Wright

pete said:
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?
 
W

Walter Roberson

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.
 
P

pete

Chris said:
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.
 
C

Chris Dollin

pete said:
Chris said:
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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top