🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #309445

chunk2int (or str2int) how it SHOULD work?

#309445
From: (fir)
Date: Thu, 14 Sep 2017 21:07
61 lines
4531 bytes
i need to define most general purspose function 
that i will be using in various codes just to 
extract integers form various texts 

if given word is just pure integer like "123" "-300" 
it is strightforward, but what if such word is a nomber which is somewhat polluted like "(123)" or "(123" "^123" 
"123v" "12 3" "a123" and so on..? what is most logical and most wiidespread to use? 

right now i got two functions, one is a wrapper on strtol 
so it worx like strtol second is also wrapper on strtol 
but as strtol fails on letters preceeding numbers i wrote one that skips those letters and then calls strtol 
(they both also give output info if no number was extracted or out of range errr do appear) 

those are example results of their work 

               a              NIL               NIL 
               b              NIL               NIL 
               c              NIL               NIL 
               d              NIL               NIL 
               1                1                 1 
               2                2                 2 
               3                3                 3 
               4                4                 4 
              a1              NIL                 1 
              a2              NIL                 2 
              a3              NIL                 3 
              3d                3                 3 
              3h                3                 3 
            0xff              255               255 
          0xffff            65535             65535 
              0x              NIL               NIL 
        0b111001                0                 0 
             1e4                1                 1 
           -0x45              -69               -69 
              -2               -2                -2 
              a-              NIL               NIL 
              3-                3                 3 
              4-                4                 4 
             --5              NIL                -5 
               -              NIL               NIL 
               6                6                 6 
               -              NIL               NIL 
             a2a              NIL                 2 
          a-22-3              NIL               -22 
            3f4f                3                 3 
             (2)              NIL                 2 
              +6                6                 6 
             )89              NIL                89 
             =78              NIL                78 
              *4              NIL                 4 
              ^4              NIL                 4 
      7123456789            RANGE             RANGE 
     0x223344556            RANGE             RANGE 
               8                8                 8 
               9                9                 9 
            0.23                0                 0 
             .84              NIL                84 
            .12.              NIL                12 
             .23              NIL                23 

im not sure if i would in practice needed more first or more second or maybe both, or maybe i should define such functions in some way other - but how? 
Technical Details
Message-ID: <f762205f-d614-4267-813a-f181066a6ae2@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!127no298980itw.0!news-out.google.com!a26ni422qta.0!nntp.google.com!q8no444257qtb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Received: by 10.36.43.210 with SMTP id h201mr857965ita.30.1505423270695;        Thu, 14 Sep 2017 14:07:50 -0700 (PDT)
X-Received: by 10.31.161.81 with SMTP id k78mr296812vke.25.1505423270645; Thu, 14 Sep 2017 14:07:50 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!127no298980itw.0!news-out.google.com!a26ni422qta.0!nntp.google.com!q8no444257qtb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.c
Date: Thu, 14 Sep 2017 14:07:50 -0700 (PDT)
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=5.172.255.61; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.61
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f762205f-d614-4267-813a-f181066a6ae2@googlegroups.com>
Subject: chunk2int (or str2int) how it SHOULD work?
From: "(fir)" <profesor.fir@gmail.com>
Injection-Date: Thu, 14 Sep 2017 21:07:50 +0000
Lines: 60
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit