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


Groups > comp.lang.c > #111508

Re: Parsing based on 1st and 2nd spaces in a string

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Parsing based on 1st and 2nd spaces in a string
Date Sun, 04 Jun 2017 19:40:48 -0700
Organization None to speak of
Lines 36
Message-ID <lnk24rkvgv.fsf@kst-u.example.com> (permalink)
References <oh0ro2$12p$1@dont-email.me> <m2tw3vamfr.fsf@despina.home> <oh1582$vqs$2@dont-email.me> <8737bfo2j8.fsf@bsb.me.uk>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx02.eternal-september.org; posting-host="8fe7a18ee00f66a3b2c6771eb1ebbfdc"; logging-data="5379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xDI7heNJSWDOnd5rnhOG5"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:/7RU5X4iPu5QDxh3QbARa0gGHbg= sha1:gSYh0j11xKE3qyMimQVS/5bTEKc=
Xref csiph.com comp.lang.c:111508

Show key headers only | View raw


Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> DFS <nospam@dfs.com> writes:
[...]
> Another point: are you absolutely sure that strncpy is the function you
> need?  Unlike the other string functions it does

You mean "doesn't".

>                                                  append a null byte so
> you can end up with unexpected result.  And if it is the right function
> to use, the modern way is to call memcpy.  It's clearer in the the
> reader has fewer things to think about -- it's a straight data copy.
>
>> But thanks for showing isspace().  That might be handy.
>>
>>>      if(isdigit(line[0]) && isspace(line[1])){
>>>         parse_digit_and_value(line);
>>>      }else if(isdigit(line[0])){
>>>         parse_error(line,"Invalid syntax");
>>>      }else{
>>>         parse_value(line);
>>>      }
>
> You really should consider making the code as clear as this.  There is
> almost not cost to covering all the options and lot to be gained by not
> causing your readers to wonder about the other case.

Keep in mind that isdigit() takes an argument of type int, and has
undefined behavior for a negative argument other than EOF.  Usually
isdigit(foo) should be isdigit((unsigned)foo).

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Parsing based on 1st and 2nd spaces in a string DFS <nospam@dfs.com> - 2017-06-04 07:48 -0400
  Re: Parsing based on 1st and 2nd spaces in a string "Pascal J. Bourguignon" <pjb@informatimago.com> - 2017-06-04 15:53 +0200
    Re: Parsing based on 1st and 2nd spaces in a string DFS <nospam@dfs.com> - 2017-06-04 10:29 -0400
      Re: Parsing based on 1st and 2nd spaces in a string "Pascal J. Bourguignon" <pjb@informatimago.com> - 2017-06-04 21:52 +0200
        Re: Parsing based on 1st and 2nd spaces in a string DFS <nospam@dfs.com> - 2017-06-04 16:43 -0400
      Re: Parsing based on 1st and 2nd spaces in a string Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-04 22:39 +0100
        Re: Parsing based on 1st and 2nd spaces in a string Keith Thompson <kst-u@mib.org> - 2017-06-04 19:40 -0700
        Re: Parsing based on 1st and 2nd spaces in a string DFS <nospam@dfs.com> - 2017-06-05 00:08 -0400
          Re: Parsing based on 1st and 2nd spaces in a string raltbos@xs4all.nl (Richard Bos) - 2017-06-05 08:52 +0000
            Re: Parsing based on 1st and 2nd spaces in a string Robert Wessel <robertwessel2@yahoo.com> - 2017-06-05 23:51 -0500
          Re: Parsing based on 1st and 2nd spaces in a string Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-05 12:37 +0100
          Re: Parsing based on 1st and 2nd spaces in a string "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-05 12:53 -0400
  Re: Parsing based on 1st and 2nd spaces in a string Barry Schwarz <schwarzb@dqel.com> - 2017-06-04 11:24 -0700
    Re: Parsing based on 1st and 2nd spaces in a string DFS <nospam@dfs.com> - 2017-06-04 16:43 -0400

csiph-web