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!
Actually it is correct. I don't know where you see anything wrong, but
I have been making programs with that method for a while.
Here is how I thought of it:
cin.get(var, array); automatically throws a '\0' NULL character. ASCII 0
to the end of the array after it receives input, so I though that if
gets(); didn't, that I would. So I stuck a piece of code to the end
which puts the null character where it is supposed to. Remember, a NULL
character when outputing a string signifies the end of the string.
Anything afterwards is ignored. I have tried this method with BCOS2,
MS-VC++, and the GNU compilers. Works great. \0 is one character by
the way, just like \n and \t. They are macros.
PEACE!
-Dave
1:3612/333
333:1/1
davidvh@ibm.net
--- PCBoard (R) v15.3/100
---------------
* Origin: Destiny BBS: LightBar Central (1:3612/333)
|