TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: RIMU ATKINSON
from: TOM TORFS
date: 1998-03-26 15:11:00
subject: reading input from stdin (was: I`m an id15:11:5203/26/98

Rimu Atkinson wrote in a message to Phil Ohl:
 RA> use the gets() function to get a line of text from stdin.
I think there's a "don't" missing in that sentence somewhere :-)
 RA> eg: 
 RA> char name[40];
 RA> gets(name);
Oops... one sticking key or overactive user will crash/coredump/otherwise 
mutilate your program.
Try:
char name[40],*p;
fgets(name,40,stdin);
/* if you wish to remove the newline to duplicate gets() functionality: */
if ((p=strchr(name,'\n'))!=NULL)
   *p = '\0';
greetings,
Tom
tomtorfs@village.uunet.be
--- timEd/2 1.10+
---------------
* Origin: 80X86 BBS 32-15-24.62.32 V.34/V.FC (24h/24h) (2:292/516)

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™.