| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | complete idiot or what? |
JB> Complete idiot's guide to C++ says the following.
JB> // Listing 23_5
JB> #include
JB> #include
JB> int main()
JB> {
JB> char* name;
JB> name = new char;
That establishes name as a ONE BYTE field. That's going to limit the
number of names available to 26 (like Wales, only their names are longer
than 1 character, even though there are <= 26 of them). You may wish to
use:
name = new char [20];
JB> strcpy(name,"PAUL");
You KNOW that this will be done in a crucial app. by your biggest
client.
JB> cout << name;
JB> delete name;
delete [] name; // I've always thought the placement of
[] was crazy, but that's the standard
JB> return 0;
JB> }
JB> is that combination of new and strcpy "right"?
It may be the kiss of death in an app. compiled in release mode.
JB> it looks highly suspicious to me.
JB> Something like "name = new char[5]" seems better to me, would that
JB> be correct?
Yes, although 5 might still be a little short.
þ CMPQwk 1.42 999
--- Maximus/2 3.01
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)SEEN-BY: 633/267 270 @PATH: 106/2000 1 379/1 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™.