TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DAVID VAN HOOSE
from: BRUCE WEDDING
date: 1998-04-03 12:03:00
subject: reading input from stdin (was: I`m an id12:03:4204/03/98

DVH> char name[40];
DVH> gets(name);
DVH> name[40]='\0';
TT> That still leaves the problem that you're writing to memory that
TT> isn't yours. Your array is only 40 characters long and you try to
TT> access the 41st element!
 DVH> Actually it is correct.  I don't know where you 
 DVH> see anything wrong, but
 DVH> I have been making programs with that method for a while.
 DVH> Here is how I thought of it:
 
It is not correct, and the fact that you have done this for a while is 
irrelevant.  The array name is 40 characters long.  These are accessed 0-39.  
When you write a 0 to name[40], you are writing to memory you don't own and 
it will blow up one day.
 
Bruce
--- Maximus/2 3.01
---------------
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)

SOURCE: echomail via exec-pc

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™.