| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | C++ strings and arrays |
Kurt Kuzba, In a message on 16 September, to Kenneth Dunn, wrote : KK> KD> RT> char name[9][9]; KK> KD> RT> strcpy(name[0],"Trevor"); KK> KD> strncpy() is safer, it is like strcpy() except it takes KK> KD> another agrument limiting the maximum number of KK> KD> characters to copy. KK> Right. You can never be too safe when it comes to observing KK> character array boundaries. Bugs can creep in unseen. Unfortunately I forgot that strncpy doesn't automatically null terminate. Which can be just as much of a problem as overwriting. What I find is the strn* functions are a little inconsistant. My reasoning: the logical design would be copy at most n-1 and terminate with a null character instead of having to allocate n+1 characters and putting a null character on the end if n items where copied. Never mind, just my line of thinking. Knew there was a good reason for using my own custom fuctions :-) ... * ATP/Linux 1.42 * --- Renegade v10-05 Exp* Origin: The Hairless Girls' BBS Mt Eden Auckland NZ (3:772/500) SEEN-BY: 396/1 622/419 632/0 371 633/260 267 270 371 634/397 635/506 728 810 SEEN-BY: 639/252 670/218 @PATH: 772/500 1 270/101 396/1 633/260 635/506 728 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™.