RA>> char name[40];
RA>> gets(name);
DVH> If you do that verbatim, you will have an overflow problem with all
DVH> known compilers. This is how that should be:
DVH> char name[40];
DVH> gets(name);
DVH> name[40]='\n';
DVH> You have to put a NULL on the end or it will have an overflow problem.
DVH> I believe you have to do that with 'fgets' as well..
DVH> Just put the null character on the very end of the array.
DVH> Hope you like my advice. Peace!
That's WORSE. Sorry.
'\n' is not null, it's EOL (end of line)
name[40] is the first byte AFTER the array.
and it doesn't prevent gets from writing like 200 characters, or even
42.
fgets has _no_problem_ with that, though -- if you set the maximum
number of characters properly.
matju
--- Terminate 4.00/Pro
---------------
* Origin: The Lost Remains Of SatelliteSoft BBS (1:163/215.42)
|