TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DAVID VAN HOOSE
from: DARIN MCBRIDE
date: 1998-04-02 08:51:00
subject: reading input from stdin (was: I`m an id08:51:2804/02/98

DVH> char name[40];
DVH> gets(name);
DVH> name[40]='\0';
name[40] doesn't exist.  That is one past the end of the array.
char name[40]; creates an array of 40 chars, from 0 to 39.  When you try to 
access #40 (not the 40th one - this is the 41st!), you are accessing beyond 
the array boundaries.
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 see anything wrong, but
Tom saw that you are accessing beyond the array boundaries.
 DVH> MS-VC++, and the GNU compilers. Works great. \0 is one character by
 DVH> the way, just like \n and \t.  They are macros.
\0, \n, and \t are not macros, but escape sequences.  The difference is 
huge... macros won't be expanded inside strings, escape sequences won't be 
converted outside of strings.
#define A blah
\0  /* invalid */
A  /* becomes blah */
'\0' /* becomes the nul character */
'A' /* is just the character A */
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

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