Hi John,
On 03 Apr 98, 10:12, you wrote to David Van Hoose
DVH>>> char name[40];
DVH>>> gets(name);
DVH>>> name[40]='\0';
>>
TT>>> That still leaves the problem that you're writing to memory
TT>>> that isn't yours. Your array is only 40 characters long and
TT>>> you try to access the 41st element!
>>
>> Actually it is correct. I don't know where you see anything
>> wrong,
JR> I think Tom means that name[40]='\0' should be name[39]='\0'
JR> since C/C++ is zero based (i.e 0 is always the first element
JR> hence 39 is the fortieth and 40 is the fortyfirst).
__AND__ the problem that gets() does write outside the forty byte array if
the user enters more than 39 characters!
Avoid gets() AT __ALL__ COST !!!
Greetings from
_____
/_|__| Auke Reitsma, Delft, The Netherlands.
/ | \ --------------------------------------
--- GEcho 1.00
---------------
* Origin: Home by the C (Auke.Reitsma@net.hcc.nl) (2:281/400.20)
|