Hello David.
01 Apr 98 15:19, David Van Hoose wrote to Tom Torfs:
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 see anything wrong, but
DVH> I have been making programs with that method for a while.
DVH> Here is how I thought of it:
You missed the point here, David. I'm sure you know this, but it
slipped past you.
An array is base 0, meaning that the first subscript is 0.
When you declare an array like this:
char name[40];
you have reserved 40 elements, the first being name[0] and the
last being name[39].
When you place anything in name[40] you have gone out of bounds.
The NUL character belongs in name[39].
Does any of this ring a bell?
-Roger
--- Msged/386 4.20 beta 3kl3
(1:273/404@fidonet)
---------------
* Origin: Box Of Rotting Corpses BBS, Upper Darby, PA, USA
|