Article View: alt.comp.lang.learn.c-c++
Article #393Re: scanf and default values
From: Paul Lutus
Date: Sat, 16 Jan 1999 00:00
Date: Sat, 16 Jan 1999 00:00
47 lines
2059 bytes
2059 bytes
Do not use scanf, a risky and quirky function. Instead, use this:
char buff[128];
printf("Press Enter: ");
fgets(buff,128,stdin);
This is also a better way to acquire inputs of all kinds from the user.
Paul Lutus
mbt4w wrote in message <36A0C0CC.9E2E7172@overthere.com>...
>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:
<77qtpe$nn2$1@remarQ.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36A0C0CC.9E2E7172@overthere.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,e9490d8fa974b2a4 X-Google-Attributes: gidf8d38,public X-Google-Thread: 161995,e9490d8fa974b2a4 X-Google-Attributes: gid161995,public X-Google-Thread: 114592,e9490d8fa974b2a4 X-Google-Attributes: gid114592,public From: "Paul Lutus" <nospam@nosite.com> Subject: Re: scanf and default values Date: 1999/01/16 Message-ID: <77qtpe$nn2$1@remarQ.com> X-Deja-AN: 433433411 References: <36A0C0CC.9E2E7172@overthere.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: newsabuse@remarQ.com X-Trace: 916519534 TQWU6NOQOE4A0D0E5C usenet52.supernews.com Organization: Posted via RemarQ, http://www.remarQ.com - Discussions start here! Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.os.msdos.language