TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Bo Simonsen
from: Pascal Schmidt
date: 2004-01-27 22:50:20
subject: Re: [C] Question about external variable initialization

Hi Bo! :-)

 PS>> Keep care that your strings are always 0-terminated, otherwise this
 PS>> will run off the end of the string in strlen().
 BS> Yes the extra byte isn't nessersary after I did think of.
What I meant is that it is better to use/code something like strndup(). The
input string could miss a \0 character itself, in which case strdup() goes
off the end of the allocated memory of the string.

 BS> I get in a NULL terminated string:
 BS> H e l l o   W o r l d  \0   <- text + x
 BS> 0 1 2 3 4 5 6 7 8 9 10 11   <- x
 BS> strlen will return 11. So there will be space for \0.
No, strlen will return 10.

Ciao
Pascal

--- Msged/LNX 6.1.1
* Origin: SYS 64738 (1:153/401.2)
SEEN-BY: 633/267 270
@PATH: 153/401 307 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.