| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: [C] Question about external variable initialization |
PS> Hi Bo! :-) Hi Pascal 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. PS> What I meant is that it is better to use/code something PS> like strndup(). The input string could miss a \0 PS> character itself, in which case strdup() goes off the PS> end of the allocated memory of the string. Well the point was to make strdup, if it's not existing, I really doubt that strndup would exist. 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. PS> No, strlen will return 10. Yes that's why we need a extra one! :) Bo --- Maximus/UNIX 3.03b* Origin: The Night Express - Roennede, Dk (2:236/100) SEEN-BY: 633/267 270 @PATH: 236/100 237/9 20/11 106/1 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™.