TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DAVID VAN HOOSE
from: ROGER SCUDDER
date: 1998-03-29 02:11:00
subject: reading input from stdin (was: I`m an id02:11:4603/29/98

Hello David.
27 Mar 98 15:13, David Van Hoose wrote to Tom Torfs:   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.
 So then why did you put a newline on the end?
 
DVH> I believe you have to do that with 'fgets' as well..
 No fgets prevents an overflow problem by limiting the number
 of characters that it will copy to the array.  There can be
 a problem with character left over in stdin after a call to
 fgets though, but that's easy to work around.
DVH> Just put the null character on the very end of the array.
 That's one possible way to deal with it.
DVH> Hope you like my advice. Peace!
 Thanks for sharing :-)
 -Roger
--- Msged/386 4.20 beta 3kl3
(1:273/404@fidonet)
---------------
* Origin: Box Of Rotting Corpses BBS, Upper Darby, PA, USA

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.