Article View: alt.comp.lang.learn.c-c++
Article #392scanf and default values
From: mbt4w
Date: Sat, 16 Jan 1999 00:00
Date: Sat, 16 Jan 1999 00:00
35 lines
1600 bytes
1600 bytes
Is there a way to allow a null input for scanf?
I need to be able to just press [enter] to return 0, when prompting for
a
user input. Basic's "input x" works this way and is very useful when
prompting
with default values. Maybe there is another command more like basic's
"input".
scanf("%f",&x); seems to require an entry prier to pushing [enter].
If you only press [enter] scanf still waits for input.
test.c does not work the same as test.bas.. test.c requires you type [0]
then [enter].
In test.bas you just press [enter] to return 0.
/** test.c **/
amount= 5.3
printf("Enter a value <%d> ",amount);
scanf("%d",&f);
if (x1 != 0) amount=x1;
REM ** test.bas **
amout= 5.3
PRINT "Enter a value. <"; amount; "> ";
INPUT x
IF x <> 0 THEN amount = x
Maybe I need to pre-stuff the input buffer with a leading zero? If this
is what is needed,
how would it be done.
Thanks
Technical Details
Message-ID:
<36A0C0CC.9E2E7172@overthere.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,e9490d8fa974b2a4,start X-Google-Attributes: gidf8d38,public X-Google-Thread: 114592,e9490d8fa974b2a4,start X-Google-Attributes: gid114592,public X-Google-Thread: 161995,e9490d8fa974b2a4,start X-Google-Attributes: gid161995,public From: mbt4w <DontlikeSpam@overthere.com> Subject: scanf and default values Date: 1999/01/16 Message-ID: <36A0C0CC.9E2E7172@overthere.com> X-Deja-AN: 433362385 Content-Transfer-Encoding: 7bit Organization: Verio East Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.os.msdos.language