Re: i need help about Turbo C
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Mon, 17 Jul 2006 21:11:55 GMT
"lovecreatesbeauty" <lovecreatesbeauty@xxxxxxxxx> writes:
Tom St Denis wrote:
You need to add a "\n" or the printf won't always show. The stream is
only guaranteed to flush if you send a newline.
Also your scanf doesn't eat the newline [that the user enters]. So
when you get to the second scanf() you get just the newline.
At the second time, every input function will be fed with the newline
left by the previous scanf.
You need to flush the input stream [hint: don't use fflush on it].
You may also want to try and use fgets() instead of scanf [hint:
buffer overflows].
What you said are really good points. Someone, e.g. Keith Thompson,
recommended to use scanf for numbers. Do you agree?
Perhaps you have me confused with someone else.
Sure, you can use scanf for numbers. Doing so doesn't present the
same overflow possibilities as an unbounded scanf("%s"). But I
usually recommend using fgets() to read a line at a time, then
sscanf() to parse the line once it's been read. (fgets() has its
problems, but they're easier to work around than scanf()'s problems.)
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- References:
- i need help about Turbo C
- From: pipito
- Re: i need help about Turbo C
- From: Tom St Denis
- Re: i need help about Turbo C
- From: lovecreatesbeauty
- i need help about Turbo C
- Prev by Date: Re: Simple RegExp function
- Next by Date: Re: i need help about Turbo C
- Previous by thread: Re: i need help about Turbo C
- Next by thread: Re: i need help about Turbo C
- Index(es):
Relevant Pages
|