|
question about 'operator new'
here is the code:
The output of strlen is 15?
I don't get it.
Is this just because of random garbage in memory?
"If at first you DO succeed...try not to look astonished!!"
BASSOFeeSH@aol.com
BASSOFeeSH
><>
Edited by - Michael Tanczos on 6/5/00 11:10:18 PM
-- What would Sweetness do?
Yes, it's because of "random garbage". Since you are dynamically allocating the memory, there is no guarantee that the memory will be set to zero.
To get the desired result (0), you must set the first place of name to \0.
There is usually no need to do this, since you will probably use string functions (such as strcpy() or gets()) that will make sure that the \0 is at the correct place, before you use the strlen() function.
/. Muzzafarath
Mad House Software
Edited by - Muzzafarath on June 6, 2000 12:26:51 PM
To get the desired result (0), you must set the first place of name to \0.
|
There is usually no need to do this, since you will probably use string functions (such as strcpy() or gets()) that will make sure that the \0 is at the correct place, before you use the strlen() function.
/. Muzzafarath
Mad House Software
Edited by - Muzzafarath on June 6, 2000 12:26:51 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Unrelated Q
How''d you guys put the code into that neat white background?
How''d you guys put the code into that neat white background?
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
It's easy Nazrix, put all code in [ source] code goes here [ /source] blocks (without the spaces in the tags).
I noticed that it doesn't color void when it's inside ()... Weird.
/. Muzzafarath
Mad House Software
Edited by - Muzzafarath on June 6, 2000 12:24:09 PM
|
I noticed that it doesn't color void when it's inside ()... Weird.
/. Muzzafarath
Mad House Software
Edited by - Muzzafarath on June 6, 2000 12:24:09 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
|
PS Muzzafarath, if you put void with spaces around it, it is blue...just figured that out

Edited by - Nazrix on June 6, 2000 1:50:30 PM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
|
Cool...
lntakitopi@aol.com | http://geocities.com/guanajam/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement