TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Kieran Haughey
from: David Nugent
date: 1995-12-24 13:00:36
subject: c

KH> int main()
 KH> {
 KH>     char name[100],*validname;      /* validname should work like that */
 KH>     char done=0;

 KH>     printf("Enter Name: ");
 KH>     gets(name);     /* I always prefer gets to scanf */

If you were using the GNU library, you'd get "This program uses gets()
and is therefore dangerous" during the call (you can disable this if
you're really desperate).

As to the reason why, then run the resulting program, then press and hold
down any key at all until > 100 characters have been entered. THEN see
how useful your program is. :)

fgets() is only a little extra typing, and performs the same functionality
and is safe because you can limit input (although exactly what you do with
characters after the 99th is up to you). There is also no reason to assume
that stdin is a terminal/keyboard - someone may have redirected it from
elsewhere.

Summary: gets() is dangerous - don't use it.

--- MaltEd/2 1.0.b6
* Origin: Decadence BBS & Unique Computing - What a team! (3:632/348)
SEEN-BY: 50/99 620/243 623/630 632/103 348 360 998 633/371 634/384 388
SEEN-BY: 635/301 502 503 544 727 639/252 711/401 409 410 413 430 510 808 809
SEEN-BY: 711/932 934 712/515 713/888 714/906 800/1 7877/2809
@PATH: 632/348 635/503 50/99 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

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