Re: advice
From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 11/21/03
- Next message: Jenski182: "Re: advice"
- Previous message: Jenski182: "Re: advice"
- In reply to: Jenski182: "advice"
- Next in thread: Jenski182: "Re: advice"
- Reply: Jenski182: "Re: advice"
- Reply: Jenski182: "Re: advice"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 20 Nov 2003 23:19:25 GMT
"Jenski182" <jenski182@aol.comnojunk> wrote in message
news:20031120181038.01467.00000501@mb-m20.aol.com...
> ok this is my code :o)
> how can i stop it terminating after entering a string of more than 128
chars
> long? Thanks Jen x
[snip]
> //Get a string from stdin.
> gets (input);
[snip]
Never, never, never, *never* use gets(). Period.
See http://www.eskimo.com/~scs/C-faq/q12.23.html
(Read the whole FAQ, while you're at it, the returns
are well worth the effort imo.)
Use fgets(), which does feature a parameter with which
you can restrict the amount of input text stored.
Since it's outside control of the language, you'll still
need to deal with any possible 'extraneous' input that
might still reside in an OS's input buffer. Just use a
loop which extracts characters until a newline or EOF is
encountered.
-Mike
- Next message: Jenski182: "Re: advice"
- Previous message: Jenski182: "Re: advice"
- In reply to: Jenski182: "advice"
- Next in thread: Jenski182: "Re: advice"
- Reply: Jenski182: "Re: advice"
- Reply: Jenski182: "Re: advice"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|