| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | c |
On 24 Dec 95 13:00, David Nugent wrote to Kieran Haughey:
Hi David,
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 */
DN> If you were using the GNU library, you'd get "This program uses
gets() and
DN> is therefore dangerous" during the call (you can disable this if you're
DN> really desperate).
DN> As to the reason why, then run the resulting program, then press and hold
DN> down any key at all until > 100 characters have been entered. THEN see how
DN> useful your program is. :)
Well you can tell who's going to be going through all his programs to
replace his gets() calls :)..
DN> fgets() is only a little extra typing, and performs the same functionality
DN> and is safe because you can limit input (although exactly what you do with
DN> characters after the 99th is up to you). There is also no reason to assume
DN> that stdin is a terminal/keyboard - someone may have redirected it from
DN> elsewhere.
Yes, but isn't gets() taking from the stdin anyway?.... so either way
fgets(buffer,100,stdin); would be roughly the same as gets(buffer); except
for lengths... but thinking about it I would prefer fgets, because as you
said I can limit input :)..
DN> Summary: gets() is dangerous - don't use it.
Thanx, I have never seen anyone elsewhere being warned about this, so I
would have continued to use that dangerous little command :).. * Origin: -=> The Last Stand Against Sanity <=- (3:711/413.17)SEEN-BY: 50/99 620/243 623/630 711/401 409 410 413 420 423 430 510 808 809 SEEN-BY: 711/932 934 712/515 713/888 714/906 800/1 7877/2809 @PATH: 711/413 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™.