Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

about string and character

 
 
Keith Thompson
Guest
Posts: n/a
 
      12-03-2007
santosh <(E-Mail Removed)> writes:
> Dik T. Winter wrote:
>> In article <4753d12c$0$30525$(E-Mail Removed)> "Charlie Gordon"
>> <(E-Mail Removed)> writes:

[...]
>> > strlen("abc\0def") -> 3
>> >
>> > Are 'd', 'e', 'f', and the final '\0' not part of the object
>> > "abc\0def" ? Is "abc\0def" not a string ?

>>
>> They are a single object. But only the firt part is a string.

>
> Then the name "character string literal" would be misleading.


This is acknowledged in a footnote in C99 6.4.5:

A character string literal need not be a string (see 7.1.1),
because a null character may be embedded in it by a \0 escape
sequence.

--
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
 
 
 
 
Joe Wright
Guest
Posts: n/a
 
      12-03-2007
Chris Torek wrote:
> In article <(E-Mail Removed)>
> Joe Wright <(E-Mail Removed)> wrote:
>> char str[] = "Hello";
>> The sizeof str is 6 while strlen(str) is 5.

>
> Indeed.
>
>> While the nul is of type char it's not really a character, is it?

>
> It is definitely a "char". It is a valid character, although it
> is not what some people call a character. (Some people call *me*
> a character. ) As usual, this all comes down to the general
> problem of making sure that everyone involved in some discussion
> intents the same semantics when they use the same words. (I
> occasionally see people say things like "bah, mere semantics", yet
> "semantics" are essential to correct understanding.)
>
> As another data point, note that strchr() and strrchr() will
> find the terminating '\0'. For instance:
>
> char s[] = "Hello";
> char *p = strchr(s", '\0');
>
> will leave p non-NULL, pointing to the '\0' stored in s[5]. So we
> can say that for some Standard C functions dealing with strings,
> the terminating '\0' *is* "part of the string"; for others (e.g.,
> strlen()), it is excluded.


All good and true, nonetheless I contend, given ASCII, that codes from 0
through 127 are values of type char but not what I call a character. The
character values start at 32 (space) through 126. Please consider..

| 0 NUL| 1 SOH| 2 STX| 3 ETX| 4 EOT| 5 ENQ| 6 ACK| 7 BEL|
| 8 BS | 9 HT | 10 LF | 11 VT | 12 FF | 13 CR | 14 SO | 15 SI |
| 16 DLE| 17 DC1| 18 DC2| 19 DC3| 20 DC4| 21 NAK| 22 SYN| 23 ETB|
| 24 CAN| 25 EM | 26 SUB| 27 ESC| 28 FS | 29 GS | 30 RS | 31 US |
| 32 | 33 ! | 34 " | 35 # | 36 $ | 37 % | 38 & | 39 ' |
| 40 ( | 41 ) | 42 * | 43 + | 44 , | 45 - | 46 . | 47 / |
| 48 0 | 49 1 | 50 2 | 51 3 | 52 4 | 53 5 | 54 6 | 55 7 |
| 56 8 | 57 9 | 58 : | 59 ; | 60 < | 61 = | 62 > | 63 ? |
| 64 @ | 65 A | 66 B | 67 C | 68 D | 69 E | 70 F | 71 G |
| 72 H | 73 I | 74 J | 75 K | 76 L | 77 M | 78 N | 79 O |
| 80 P | 81 Q | 82 R | 83 S | 84 T | 85 U | 86 V | 87 W |
| 88 X | 89 Y | 90 Z | 91 [ | 92 \ | 93 ] | 94 ^ | 95 _ |
| 96 ` | 97 a | 98 b | 99 c |100 d |101 e |102 f |103 g |
|104 h |105 i |106 j |107 k |108 l |109 m |110 n |111 o |
|112 p |113 q |114 r |115 s |116 t |117 u |118 v |119 w |
|120 x |121 y |122 z |123 { |124 | |125 } |126 ~ |127 DEL|

It's easy for me to see ACK (6) as char type but I can't see it as a
character. This argument is a mole-hill, not a mountain.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
 
Reply With Quote
 
 
 
 
Joe Wright
Guest
Posts: n/a
 
      12-03-2007
Willem wrote:
> Chris wrote:
> ) will leave p non-NULL, pointing to the '\0' stored in s[5]. So we
> ) can say that for some Standard C functions dealing with strings,
> ) the terminating '\0' *is* "part of the string"; for others (e.g.,
> ) strlen()), it is excluded.
>
> Doesn't strlen return the index of the first '\0' in a string ?
>
>
> SaSW, Willem


No. 'size_t strlen(const char *s);' returns an unsigned integer count of
the number of characters before the terminating nul.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      12-03-2007
Joe Wright said:

> Willem wrote:


<snip>

>> Doesn't strlen return the index of the first '\0' in a string ?
>>

> No. 'size_t strlen(const char *s);' returns an unsigned integer count of
> the number of characters before the terminating nul.


How does that result differ from the index of the first '\0' in a string?

--
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
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      12-04-2007
Joe Wright wrote:
> Willem wrote:
>> Chris wrote:
>>
>>> will leave p non-NULL, pointing to the '\0' stored in s[5]. So
>>> we can say that for some Standard C functions dealing with
>>> strings, the terminating '\0' *is* "part of the string"; for
>>> others (e.g., strlen()), it is excluded.

>>
>> Doesn't strlen return the index of the first '\0' in a string ?

>
> No. 'size_t strlen(const char *s);' returns an unsigned integer
> count of the number of characters before the terminating nul.


Which (index, not address) is the same thing. If the char array
doesn't hold a string it causes UB.

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

 
Reply With Quote
 
Joe Wright
Guest
Posts: n/a
 
      12-04-2007
Richard Heathfield wrote:
> Joe Wright said:
>
>> Willem wrote:

>
> <snip>
>
>>> Doesn't strlen return the index of the first '\0' in a string ?
>>>

>> No. 'size_t strlen(const char *s);' returns an unsigned integer count of
>> the number of characters before the terminating nul.

>
> How does that result differ from the index of the first '\0' in a string?
>

It doesn't. Apologies to all.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-04-2007
Joe Wright <(E-Mail Removed)> writes:
[...]
> All good and true, nonetheless I contend, given ASCII, that codes from
> 0 through 127 are values of type char but not what I call a
> character. The character values start at 32 (space) through
> 126. Please consider..


[ASCII chart snipped]

> It's easy for me to see ACK (6) as char type but I can't see it as a
> character. This argument is a mole-hill, not a mountain.


It's a character as the term is defined by the C standard. See C99
3.7 and 3.7.1.

--
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
 
Eric Sosman
Guest
Posts: n/a
 
      12-04-2007
Joe Wright wrote:
> [...]
> All good and true, nonetheless I contend, given ASCII, that codes from 0
> through 127 are values of type char but not what I call a character. The
> character values start at 32 (space) through 126. Please consider..
> [...]
> It's easy for me to see ACK (6) as char type but I can't see it as a
> character. This argument is a mole-hill, not a mountain.


Poor guy. I guess one could get along without tabs,
but C without newlines must be pretty hard to manage ...

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
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