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)
|