Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.msdos.programmer > #12

Re: C scanf()

From T. Ment <t.ment@protocol.invalid>
Newsgroups alt.msdos.programmer, comp.os.msdos.programmer
Subject Re: C scanf()
Date 2019-03-01 16:25 +0000
Organization A noiseless patient Spider
Message-ID <slki7ehmsas3padn33orensjs8io2cebo0@4ax.com> (permalink)
References <fv0g7eta1mngc8stdge4p3k87t1kpem32v@4ax.com> <q5asup$s8b$1@gioia.aioe.org> <alpine.BSF.2.02.1903010822290.33351@frieza.hoshinet.org>

Cross-posted to 2 groups.

Show all headers | View raw


On Fri, 1 Mar 2019 08:22:55 -0500, Steve Nickolas <usotsuki@buric.co>
wrote:

>My approach to using scanf()...Don't.  Use fgets() and sscanf().

In the scanf() help, Borland C++ 3.1 has similar advice:


> The combination of gets or fgets followed by sscanf is safe and easy, and
> therefore recommended over scanf.

But like an old wives tale, it misinforms. There are safe ways to use
scanf().

With fgets() fixed buffer length, a long line with trailing whitespace
is a problem. You must either ignore it, or write special code to see if
there's something else out there besides whitespace.

With the right format string, scanf() does that automatically. It can be
done, I showed how.

I don't need to change your mind, I only want to present an alternate
view of scanf(). Even the technical elite have old wives tales. I don't
believe all of them.

Back to alt.msdos.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

C scanf() T. Ment <triflemenot@protocol.invalid> - 2019-02-28 16:43 +0000
  Re: C scanf() T. Ment <t.ment@protocol.invalid> - 2019-02-28 22:07 +0000
  Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-01 10:10 +0100
    Re: C scanf() Steve Nickolas <usotsuki@buric.co> - 2019-03-01 08:22 -0500
      Re: C scanf() T. Ment <t.ment@protocol.invalid> - 2019-03-01 16:25 +0000
        Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-01 17:39 +0100
          Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-01 18:08 +0000
            Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-01 18:22 +0000
            Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-01 19:04 +0000
              Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-01 19:15 +0000
                Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-01 19:20 +0000
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-01 19:31 +0000
                Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-01 21:29 +0000
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-01 21:53 +0000
                Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-01 22:20 +0000
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-01 22:48 +0000
                Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-01 23:34 +0000
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-01 23:41 +0000
                Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-02 00:09 +0000
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 00:14 +0000
                Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-02 00:19 +0000
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 00:32 +0000
                Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-02 00:44 +0000
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-02 09:55 +0100
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 15:54 +0000
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-02 19:43 +0100
                Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-02 18:58 +0000
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-02 20:16 +0100
                Re: C scanf() "Kerr-Mudd,John" <notsaying@invalid.org> - 2019-03-03 08:08 +0000
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-03 10:05 +0100
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-03 14:56 +0000
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 19:06 +0000
                Re: C scanf() Sjouke Burry <burrynulnulfour@ppllaanneett.nnll> - 2019-03-02 20:12 +0100
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 19:23 +0000
                Re: C scanf() Sjouke Burry <burrynulnulfour@ppllaanneett.nnll> - 2019-03-02 21:39 +0100
                Re: C scanf() "Gene Buckle" <gene.buckle@bbs.retroarchive.org.remove-zcb-this> - 2019-03-05 08:53 -0800
                Re: C scanf() "Gene Buckle" <gene.buckle@bbs.retroarchive.org.remove-zcb-this> - 2019-03-05 08:53 -0800
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-05 17:45 +0000
                Re: C scanf() "Kerr-Mudd,John" <notsaying@invalid.org> - 2019-03-05 19:59 +0000
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-02 20:23 +0100
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 19:53 +0000
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-02 21:50 +0100
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 21:19 +0000
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-02 22:46 +0100
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 22:09 +0000
                Re: C scanf() Rod Pemberton <invalid@lkntrgzxc.com> - 2019-03-02 17:05 -0500
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 22:43 +0000
                Re: C scanf() Rod Pemberton <invalid@lkntrgzxc.com> - 2019-03-02 17:07 -0500
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-03 07:44 +0100
                Re: C scanf() Rod Pemberton <invalid@lkntrgzxc.com> - 2019-03-03 02:20 -0500
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-03 09:57 +0100
                Re: C scanf() Steve Nickolas <usotsuki@buric.co> - 2019-03-03 02:22 -0500
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-02 09:39 +0100
                Re: C scanf() Rod Pemberton <invalid@lkntrgzxc.com> - 2019-03-01 16:58 -0500
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-01 22:39 +0000
                Re: C scanf() Rod Pemberton <invalid@lkntrgzxc.com> - 2019-03-01 21:10 -0500
                Re: C scanf() rridge@csclub.uwaterloo.ca (Ross Ridge) - 2019-03-01 22:46 +0000
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-01 22:55 +0000
            Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-01 21:15 +0100
          Re: C scanf() Rod Pemberton <invalid@lkntrgzxc.com> - 2019-03-01 16:58 -0500
            Re: C scanf() T. Ment <t.ment@protocol.invalid> - 2019-03-01 22:30 +0000
            Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-02 09:29 +0100
              Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 16:10 +0000
                Re: C scanf() "R.Wieser" <address@not.available> - 2019-03-02 19:54 +0100
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-02 19:12 +0000
            Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-04 16:57 +0000
              Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-04 18:59 +0000
                Re: C scanf() Rod Pemberton <invalid@lkntrgzxc.com> - 2019-03-04 23:52 -0500
                Re: C scanf() src153 <src153@protocol.invalid> - 2019-03-05 15:56 +0000

csiph-web