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


Groups > comp.lang.c > #111691 > unrolled thread

memscan() function or equivalent

Started by"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
First post2017-06-07 06:16 -0700
Last post2017-06-07 08:53 -0700
Articles 20 on this page of 122 — 18 participants

Back to article view | Back to comp.lang.c


Contents

  memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 06:16 -0700
    Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 15:47 +0200
      Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 07:15 -0700
        Re: memscan() function or equivalent scott@slp53.sl.home (Scott Lurndal) - 2017-06-07 14:34 +0000
          Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 07:42 -0700
            Re: memscan() function or equivalent scott@slp53.sl.home (Scott Lurndal) - 2017-06-07 14:45 +0000
              Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 08:07 -0700
                Re: memscan() function or equivalent jameskuyper@verizon.net - 2017-06-07 09:14 -0700
                  Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:33 -0700
        Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 16:48 +0200
          Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 08:31 -0700
            Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 17:37 +0200
              Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 08:47 -0700
                Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 18:02 +0200
                  Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:09 -0700
                    Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 18:34 +0200
                      Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:54 -0700
                        Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 19:01 +0200
                          Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 10:17 -0700
                            Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 19:53 +0200
                        Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-07 22:15 -0700
                          Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-07 22:26 -0700
                            Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-07 22:56 -0700
                              Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-07 23:03 -0700
              Re: memscan() function or equivalent scott@slp53.sl.home (Scott Lurndal) - 2017-06-07 16:10 +0000
                Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:30 -0700
          Re: memscan() function or equivalent Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-07 16:50 +0100
            Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 08:58 -0700
              Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:03 -0700
                Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:07 -0700
                Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-07 17:30 +0100
                  Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:36 -0700
                    Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-07 17:48 +0100
                      Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 09:57 -0700
                      Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-12 05:54 +0000
                  Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-07 09:48 -0700
                    Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-07 20:55 +0100
                    Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-07 22:13 +0100
                      Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-07 16:02 -0700
                        Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-08 01:26 +0100
                          Re: memscan() function or equivalent Ian Collins <ian-news@hotmail.com> - 2017-06-08 13:00 +1200
                            Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-08 09:48 +0100
                        Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-10 08:52 +0200
              Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-07 10:00 -0700
                Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 10:13 -0700
                  Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-07 11:19 -0700
                    Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-07 11:27 -0700
              Re: memscan() function or equivalent Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-07 21:18 +0100
            Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 18:18 +0200
              Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-07 21:15 +0200
                Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 21:16 +0200
                  Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-10 09:08 +0200
                    Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-10 09:56 +0200
                      Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-10 17:14 +0200
                        Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-10 17:38 +0200
                          Re: memscan() function or equivalent David Kleinecke <dkleinecke@gmail.com> - 2017-06-10 11:52 -0700
                            Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-10 20:03 +0100
                            Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-10 13:32 -0700
                            Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-10 23:40 +0200
                              Re: memscan() function or equivalent Anton Shepelev <anton.txt@gmail.com> - 2017-06-11 00:53 +0300
                                Re: memscan() function or equivalent Anton Shepelev <anton.txt@gmail.com> - 2017-06-11 01:11 +0300
                                  Re: memscan() function or equivalent Ian Collins <ian-news@hotmail.com> - 2017-06-11 10:26 +1200
                                    Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 00:32 +0200
                                      Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 10:05 +0200
                                        Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 10:06 +0200
                                        Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-11 13:19 -0700
                                    Re: memscan() function or equivalent Anton Shepelev <anton.txt@gmail.com> - 2017-06-11 02:17 +0300
                                Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-10 15:21 -0700
                                Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 00:19 +0200
                                  Re: memscan() function or equivalent Anton Shepelev <anton.txt@gmail.com> - 2017-06-11 02:15 +0300
                                  Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 10:36 +0200
                                    Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 10:46 +0200
                                Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-10 22:25 -0700
                              Re: memscan() function or equivalent "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-06-10 15:13 -0700
                              Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-10 23:21 +0100
                                Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 00:28 +0200
                                  Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-11 10:56 +0100
                                    Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 13:27 +0200
                                      Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-11 13:19 +0100
                                    Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-11 18:36 +0000
                                      Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-11 20:22 +0100
                                        Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-12 06:09 +0000
                                          Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-12 10:38 +0100
                                            Re: memscan() function or equivalent asetofsymbols@gmail.com - 2017-06-12 05:30 -0700
                                            Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-12 13:51 +0000
                                              Re: memscan() function or equivalent bartc <bc@freeuk.com> - 2017-06-12 15:04 +0100
                                        Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-12 21:26 +0000
                              Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 10:04 +0200
                                Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 10:13 +0200
                                  Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 13:38 +0200
                                    Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 14:18 +0200
                                  Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-11 09:57 -0700
                                    Re: memscan() function or equivalent Melzzzzz <Melzzzzz@zzzzz.com> - 2017-06-11 17:18 +0000
                          Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 09:53 +0200
                            Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-11 10:00 +0200
                              Re: memscan() function or equivalent "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-11 13:41 +0200
                Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 21:24 +0200
                Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 21:55 +0200
            Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-07 20:54 +0100
              Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-07 23:00 +0200
                Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-08 08:16 +0100
                  Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-08 10:55 +0200
                    Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-08 11:44 +0100
                      Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-08 13:11 +0200
                        Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-08 13:45 +0100
                          Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-08 14:51 +0200
                  Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-08 08:00 -0700
            Re: memscan() function or equivalent Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-09 12:26 -0700
              Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-10 07:24 +0100
                Re: memscan() function or equivalent Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-10 13:17 +0100
                  Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-10 17:18 +0100
                    Re: memscan() function or equivalent Ike Naar <ike@iceland.freeshell.org> - 2017-06-11 18:11 +0000
                Re: memscan() function or equivalent Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-11 15:08 -0700
                  Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-12 18:34 +0100
                    Re: memscan() function or equivalent Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-14 09:52 -0700
                      Re: memscan() function or equivalent Gareth Owen <gwowen@gmail.com> - 2017-06-14 19:56 +0100
                        Re: memscan() function or equivalent Keith Thompson <kst-u@mib.org> - 2017-06-14 12:20 -0700
                        Re: memscan() function or equivalent Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-17 06:37 -0700
                          Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-17 10:02 -0700
        Re: memscan() function or equivalent David Brown <david.brown@hesbynett.no> - 2017-06-07 16:51 +0200
          Re: memscan() function or equivalent GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-07 17:00 +0200
            Re: memscan() function or equivalent supercat@casperkitty.com - 2017-06-07 08:53 -0700

Page 1 of 7  [1] 2 3 4 5 6 7  Next page →


#111691 — memscan() function or equivalent

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 06:16 -0700
Subjectmemscan() function or equivalent
Message-ID<fc95db66-ccd5-4fbc-83bf-84cb17257d41@googlegroups.com>
Is there a function in the C Standard Library which already does this?
I looked went to the declaration of memicmp(), which was string.h, and
didn't see one that was obvious.

    // Scans forward counting how many chars match the value in c
    int memscan(char* buf, char c, int len)
    {
        int i;


        // Make sure our environment is sane    
        if (buf && len > 0)
        {
            // Scan forward until we find a non-match
            for (i = 0; i < len; i++)
            {
                if (buf[i] != c)
                    break;
            }
    
            // Indicate how many we scanned
            return(i);
    
        } else {
            // Invalid params
            return(-1);
        }
    }

Thank you,
Rick C. Hodgin

[toc] | [next] | [standalone]


#111694

FromGOTHIER Nathan <nathan.gothier@gmail.com>
Date2017-06-07 15:47 +0200
Message-ID<20170607154705.f161b2807eb2b1a8dc12d389@gmail.com>
In reply to#111691
On Wed, 7 Jun 2017 06:16:22 -0700 (PDT)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:

> Is there a function in the C Standard Library which already does this?
> I looked went to the declaration of memicmp(), which was string.h, and
> didn't see one that was obvious.
>

>     // Scans forward counting how many chars match the value in c
>     int memscan(char* buf, char c, int len)
>     {
>         int i;
> 
> 
>         // Make sure our environment is sane    
>         if (buf && len > 0)
>         {
>             // Scan forward until we find a non-match
>             for (i = 0; i < len; i++)
>             {
>                 if (buf[i] != c)
>                     break;
>             }
>     
>             // Indicate how many we scanned
>             return(i);
>     
>         } else {
>             // Invalid params
>             return(-1);
>         }
>     }
> 

I don't think there is any but your prototype seems not C inspired since most
mem- functions work on memory objects read as a sequence of unsigned char.

A more C inspired prototype would be as:

/* count the occurence number of c */
size_t memfrq(const void *s, int c, size_t n);

[toc] | [prev] | [next] | [standalone]


#111695

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 07:15 -0700
Message-ID<12fb0e96-0ac3-442d-8d04-baaef4234a85@googlegroups.com>
In reply to#111694
On Wednesday, June 7, 2017 at 9:50:27 AM UTC-4, GOTHIER Nathan wrote:
> /* count the occurrence number of c */
> size_t memfrq(const void *s, int c, size_t n);

What do these parameters equate to?  What are s, c, and n?  Can you
include the function body so I can see it at work?

Thank you,
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#111696

Fromscott@slp53.sl.home (Scott Lurndal)
Date2017-06-07 14:34 +0000
Message-ID<Z9UZA.88544$K82.32096@fx33.iad>
In reply to#111695
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
>On Wednesday, June 7, 2017 at 9:50:27 AM UTC-4, GOTHIER Nathan wrote:
>> /* count the occurrence number of c */
>> size_t memfrq(const void *s, int c, size_t n);
>
>What do these parameters equate to?  What are s, c, and n?  Can you
>include the function body so I can see it at work?

Seems fairly obvious - Source memory address, Character to search
for and Number of bytes being searched, returns the number of hits
implementation left as an exercise for the reader.

[toc] | [prev] | [next] | [standalone]


#111698

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 07:42 -0700
Message-ID<4b96a78e-555b-4378-9d82-2bb4a0651210@googlegroups.com>
In reply to#111696
On Wednesday, June 7, 2017 at 10:34:48 AM UTC-4, Scott Lurndal wrote:
> implementation left as an exercise for the reader.

Why?  Cat got your code?

Thank you,
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#111699

Fromscott@slp53.sl.home (Scott Lurndal)
Date2017-06-07 14:45 +0000
Message-ID<QjUZA.18802$5S7.13926@fx28.iad>
In reply to#111698
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
>On Wednesday, June 7, 2017 at 10:34:48 AM UTC-4, Scott Lurndal wrote:
>> implementation left as an exercise for the reader.
>
>Why?  Cat got your code?

Because any grade-schooler could write it.

[toc] | [prev] | [next] | [standalone]


#111706

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 08:07 -0700
Message-ID<2cfa3044-2046-4434-a8bc-a9a88fb0808f@googlegroups.com>
In reply to#111699
On Wednesday, June 7, 2017 at 10:45:17 AM UTC-4, Scott Lurndal wrote:
> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
> >On Wednesday, June 7, 2017 at 10:34:48 AM UTC-4, Scott Lurndal wrote:
> >> implementation left as an exercise for the reader.
> >Why?  Cat got your code?
> Because any grade-schooler could write it.

Well, that's a completely false statement and you know it, Scott. :-)

Thank you,
Rick C. Hodgin

PS - C'mon CAlive!  Exit departures imminent!

[toc] | [prev] | [next] | [standalone]


#111721

Fromjameskuyper@verizon.net
Date2017-06-07 09:14 -0700
Message-ID<0854d1e1-dea7-4ac0-901f-379a216843c0@googlegroups.com>
In reply to#111706
On Wednesday, June 7, 2017 at 11:08:07 AM UTC-4, Rick C. Hodgin wrote:
> On Wednesday, June 7, 2017 at 10:45:17 AM UTC-4, Scott Lurndal wrote:
> > "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
> > >On Wednesday, June 7, 2017 at 10:34:48 AM UTC-4, Scott Lurndal wrote:
> > >> implementation left as an exercise for the reader.
> > >Why?  Cat got your code?
> > Because any grade-schooler could write it.
> 
> Well, that's a completely false statement and you know it, Scott. :-)

True: it should be "any grade-schooler who's acquired even an elementary
understanding of C". Even many adults haven't done that yet, including several
of the people who post here regularly. Bill Cunningham certainly couldn't write
it. Whether Bart could write it would depend upon how confused he gets about
the distinctions between arrays and pointers in C, one of his big bugaboos - I
have faith in him - I'm sure he can figure out some way to misunderstand it.

[toc] | [prev] | [next] | [standalone]


#111725

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 09:33 -0700
Message-ID<9ff55531-b3ab-4064-a77b-e94a0f1fb51b@googlegroups.com>
In reply to#111721
On Wednesday, June 7, 2017 at 12:15:06 PM UTC-4, james...@verizon.net wrote:
> On Wednesday, June 7, 2017 at 11:08:07 AM UTC-4, Rick C. Hodgin wrote:
> > On Wednesday, June 7, 2017 at 10:45:17 AM UTC-4, Scott Lurndal wrote:
> > > "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
> > > >On Wednesday, June 7, 2017 at 10:34:48 AM UTC-4, Scott Lurndal wrote:
> > > >> implementation left as an exercise for the reader.
> > > >Why?  Cat got your code?
> > > Because any grade-schooler could write it.
> > 
> > Well, that's a completely false statement and you know it, Scott. :-)
> 
> True: it should be "any grade-schooler who's acquired even an elementary
> understanding of C".

I know how precisely the C gurus like to be precise in their precision.

> Even many adults haven't done that yet, including several
> of the people who post here regularly. Bill Cunningham certainly couldn't write
> it. Whether Bart could write it would depend upon how confused he gets about
> the distinctions between arrays and pointers in C, one of his big bugaboos - I
> have faith in him - I'm sure he can figure out some way to misunderstand it.

Bill could do it.  Bart could do it blind-folded with one arm tied behind
his back using a left-handed mouse and a Spanish keyboard.

Thank you,
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#111702

FromGOTHIER Nathan <nathan.gothier@gmail.com>
Date2017-06-07 16:48 +0200
Message-ID<20170607164800.a6fba9d07170ec5d056d25a0@gmail.com>
In reply to#111695
On Wed, 7 Jun 2017 07:15:04 -0700 (PDT)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:

> On Wednesday, June 7, 2017 at 9:50:27 AM UTC-4, GOTHIER Nathan wrote:
> > /* count the occurrence number of c */
> > size_t memfrq(const void *s, int c, size_t n);
> 
> What do these parameters equate to?  What are s, c, and n?  Can you
> include the function body so I can see it at work?


/*
  The "memfrq" function

  Description:

  The memfrq function count the occurrence number of c (converted as an
  unsigned char) in the initial n characters (each interpreted as unsigned
  char) of the object pointed to by s.

  Returns:

  The memfrq function returns the number of c occurences found.
*/

#include <stddef.h>

typedef unsigned char uchar_t;

size_t memfrq(const void *s, int c, size_t n)
{
  uchar_t *s0 = (uchar_t *) s;
  uchar_t c0 = (uchar_t) c;
  size_t k = 0U;

  scan:
  {
    if (n > 1)
    {
      if (*s0 == c0)
      {
        k++;
      }

      s0++;
      n--;

      goto scan;
    }

    return k;
  }
}

I took a similar C standard terminology.

[toc] | [prev] | [next] | [standalone]


#111708

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 08:31 -0700
Message-ID<520a8923-87b5-4f35-87a5-feb0361db3a5@googlegroups.com>
In reply to#111702
On Wednesday, June 7, 2017 at 10:51:22 AM UTC-4, GOTHIER Nathan wrote:
> On Wed, 7 Jun 2017 07:15:04 -0700 (PDT)
> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:
> 
> > On Wednesday, June 7, 2017 at 9:50:27 AM UTC-4, GOTHIER Nathan wrote:
> > > /* count the occurrence number of c */
> > > size_t memfrq(const void *s, int c, size_t n);
> > 
> > What do these parameters equate to?  What are s, c, and n?  Can you
> > include the function body so I can see it at work?
> 
> 
> /*
>   The "memfrq" function
> 
>   Description:
> 
>   The memfrq function count the occurrence number of c (converted as an
>   unsigned char) in the initial n characters (each interpreted as unsigned
>   char) of the object pointed to by s.
> 
>   Returns:
> 
>   The memfrq function returns the number of c occurences found.
> */
> 
> #include <stddef.h>
> 
> typedef unsigned char uchar_t;
> 
> size_t memfrq(const void *s, int c, size_t n)
> {
>   uchar_t *s0 = (uchar_t *) s;
>   uchar_t c0 = (uchar_t) c;
>   size_t k = 0U;
> 
>   scan:
>   {
>     if (n > 1)
>     {
>       if (*s0 == c0)
>       {
>         k++;
>       }
> 
>       s0++;
>       n--;
> 
>       goto scan;
>     }
> 
>     return k;
>   }
> }
> 
> I took a similar C standard terminology.

This function is different than mine.  Mine scans for a consecutive
run of characters matching c, and returns the number found.  The
first non-matching encounter stops its examination.

It's akin to x86's REPZ SCASB instruction:

    https://stackoverflow.com/questions/24221250/skip-spaces-repz-scasb

Thank you,
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#111709

FromGOTHIER Nathan <nathan.gothier@gmail.com>
Date2017-06-07 17:37 +0200
Message-ID<20170607173745.e0abfe4b44fc82735b48d606@gmail.com>
In reply to#111708
On Wed, 7 Jun 2017 08:31:49 -0700 (PDT)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:

> This function is different than mine.  Mine scans for a consecutive
> run of characters matching c, and returns the number found.  The
> first non-matching encounter stops its examination.
> 
> It's akin to x86's REPZ SCASB instruction:
> 
>     https://stackoverflow.com/questions/24221250/skip-spaces-repz-scasb

You should rather look at the strcspn function.

[toc] | [prev] | [next] | [standalone]


#111710

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 08:47 -0700
Message-ID<c85d56a2-6d46-4758-98ae-ebf47f018738@googlegroups.com>
In reply to#111709
On Wednesday, June 7, 2017 at 11:41:07 AM UTC-4, GOTHIER Nathan wrote:
> On Wed, 7 Jun 2017 08:31:49 -0700 (PDT)
> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:
> > This function is different than mine.  Mine scans for a consecutive
> > run of characters matching c, and returns the number found.  The
> > first non-matching encounter stops its examination.
> > 
> > It's akin to x86's REPZ SCASB instruction:
> >     https://stackoverflow.com/questions/24221250/skip-spaces-repz-scasb
> 
> You should rather look at the strcspn function.

Strike 2.  I must ask, are you trying to have fun at my expense,
GOTHIER?

    https://msdn.microsoft.com/en-us/library/xe8sk0x7.aspx

    "Returns the index of the first occurrence in a string, of a
     character that belongs to a set of characters."

Thank you,
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#111717

FromGOTHIER Nathan <nathan.gothier@gmail.com>
Date2017-06-07 18:02 +0200
Message-ID<20170607180219.6bd48b0762ddac21b3ba2107@gmail.com>
In reply to#111710
On Wed, 7 Jun 2017 08:47:56 -0700 (PDT)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:

> On Wednesday, June 7, 2017 at 11:41:07 AM UTC-4, GOTHIER Nathan wrote:
> > On Wed, 7 Jun 2017 08:31:49 -0700 (PDT)
> > "Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:
> > > This function is different than mine.  Mine scans for a consecutive
> > > run of characters matching c, and returns the number found.  The
> > > first non-matching encounter stops its examination.
> > > 
> > > It's akin to x86's REPZ SCASB instruction:
> > >     https://stackoverflow.com/questions/24221250/skip-spaces-repz-scasb
> > 
> > You should rather look at the strcspn function.
> 
> Strike 2.  I must ask, are you trying to have fun at my expense,
> GOTHIER?

Your specifications aren't very clear too me. Please be more specific!


> 
>     https://msdn.microsoft.com/en-us/library/xe8sk0x7.aspx
> 
>     "Returns the index of the first occurrence in a string, of a
>      character that belongs to a set of characters."

The Microsoft's documention is misleading since according to n1124.pdf:

Synopsis

  #include <string.h>
  size_t strcspn(const char *s1, const char *s2);

Description

The strcspn function computes the length of the maximum initial segment of the
string pointed to by s1 which consists entirely of characters "not" from the
string pointed to by s2.

[toc] | [prev] | [next] | [standalone]


#111719

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 09:09 -0700
Message-ID<f1cb8f09-3331-4ef4-beb4-0c890756e7cb@googlegroups.com>
In reply to#111717
On Wednesday, June 7, 2017 at 12:05:41 PM UTC-4, GOTHIER Nathan wrote:
> On Wed, 7 Jun 2017 08:47:56 -0700 (PDT)
> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:
> 
> > On Wednesday, June 7, 2017 at 11:41:07 AM UTC-4, GOTHIER Nathan wrote:
> > > On Wed, 7 Jun 2017 08:31:49 -0700 (PDT)
> > > "Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:
> > > > This function is different than mine.  Mine scans for a consecutive
> > > > run of characters matching c, and returns the number found.  The
> > > > first non-matching encounter stops its examination.
> > > > 
> > > > It's akin to x86's REPZ SCASB instruction:
> > > >     https://stackoverflow.com/questions/24221250/skip-spaces-repz-scasb
> > > 
> > > You should rather look at the strcspn function.
> > 
> > Strike 2.  I must ask, are you trying to have fun at my expense,
> > GOTHIER?
> 
> Your specifications aren't very clear too me. Please be more specific!
> 
> 
> > 
> >     https://msdn.microsoft.com/en-us/library/xe8sk0x7.aspx
> > 
> >     "Returns the index of the first occurrence in a string, of a
> >      character that belongs to a set of characters."
> 
> The Microsoft's documention is misleading since according to n1124.pdf:
> 
> Synopsis
> 
>   #include <string.h>
>   size_t strcspn(const char *s1, const char *s2);
> 
> Description
> 
> The strcspn function computes the length of the maximum initial segment of the
> string pointed to by s1 which consists entirely of characters "not" from the
> string pointed to by s2.

So, if I read that correctly, then to find the length of the characters
I'm looking for at the start of the string, I have to pass it a 254-
character array which consists of every ASCII character except ASCII-32
(a space character)?

Strike 3.

Thank you,
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#111727

FromGOTHIER Nathan <nathan.gothier@gmail.com>
Date2017-06-07 18:34 +0200
Message-ID<20170607183424.6e754863cbb87f493d25d528@gmail.com>
In reply to#111719
On Wed, 7 Jun 2017 09:09:38 -0700 (PDT)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:

> So, if I read that correctly, then to find the length of the characters
> I'm looking for at the start of the string, I have to pass it a 254-
> character array which consists of every ASCII character except ASCII-32
> (a space character)?
> 
> Strike 3.

size_t n = strcspn("incredible string", "\x20");

This should give n = 10 since the segment consisting of "incredible" count
10 characters (without null character) but it is also the index of the space
character counting from zero. Thus the Microsoft's documentation is right but
misleading since strcspn means something like string complementary span.

[toc] | [prev] | [next] | [standalone]


#111730

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 09:54 -0700
Message-ID<c249b852-65d1-402d-9a4c-1fea69278d7e@googlegroups.com>
In reply to#111727
On Wednesday, June 7, 2017 at 12:37:52 PM UTC-4, GOTHIER Nathan wrote:
> On Wed, 7 Jun 2017 09:09:38 -0700 (PDT)
> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:
> 
> > So, if I read that correctly, then to find the length of the characters
> > I'm looking for at the start of the string, I have to pass it a 254-
> > character array which consists of every ASCII character except ASCII-32
> > (a space character)?
> > 
> > Strike 3.
> 
> size_t n = strcspn("incredible string", "\x20");
> 
> This should give n = 10 since the segment consisting of "incredible" count
> 10 characters (without null character) but it is also the index of the space
> character counting from zero. Thus the Microsoft's documentation is right but
> misleading since strcspn means something like string complementary span.

Strike 4.

Yes.  That's not what I was looking for.  I'm looking for a way to get
the value 4 when I use:  memscan("$$$$hi", '$', 6)

It tells me how many of the particular character occurs repeatedly.  I
would've thought the code example I gave indicated that.

Thank you,
Rick C. Hodgin

[toc] | [prev] | [next] | [standalone]


#111733

FromGOTHIER Nathan <nathan.gothier@gmail.com>
Date2017-06-07 19:01 +0200
Message-ID<20170607190141.c3371d0540598a2a1ec9df0f@gmail.com>
In reply to#111730
On Wed, 7 Jun 2017 09:54:36 -0700 (PDT)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:

> Strike 4.
> 
> Yes.  That's not what I was looking for.  I'm looking for a way to get
> the value 4 when I use:  memscan("$$$$hi", '$', 6)
> 
> It tells me how many of the particular character occurs repeatedly.  I
> would've thought the code example I gave indicated that.

Do multiple repeatitive sequences are allowed? Which count would you prefer?
The minimum or the maximum.

[toc] | [prev] | [next] | [standalone]


#111735

From"Rick C. Hodgin" <rick.c.hodgin@gmail.com>
Date2017-06-07 10:17 -0700
Message-ID<64580232-b03d-4abe-b875-8209ae77b621@googlegroups.com>
In reply to#111733
On Wednesday, June 7, 2017 at 1:05:04 PM UTC-4, GOTHIER Nathan wrote:
> On Wed, 7 Jun 2017 09:54:36 -0700 (PDT)
> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:
> 
> > Strike 4.
> > 
> > Yes.  That's not what I was looking for.  I'm looking for a way to get
> > the value 4 when I use:  memscan("$$$$hi", '$', 6)
> > 
> > It tells me how many of the particular character occurs repeatedly.  I
> > would've thought the code example I gave indicated that.
> 
> Do multiple repeatitive sequences are allowed? Which count would you prefer?
> The minimum or the maximum.

Just the first one.  I want to know how many of a thing there are in
a row, and only in that single run / sequence.  It's why I called it
mem[scan] ... it's scanning forward for that matching character in
repetition until the count is exhausted or it's no longer found.

I even tested this one before I posted so I wouldn't get attacked for
some bit of incorrect logic.  I'm growing. :-)

Thank you,
Rick C. Hodgin

PS - I remember sitting in third grade, looking out the window, and
     wondering when recess was going to get here.  Oh, such peaceful
     days. :-)

[toc] | [prev] | [next] | [standalone]


#111736

FromGOTHIER Nathan <nathan.gothier@gmail.com>
Date2017-06-07 19:53 +0200
Message-ID<20170607195310.b55fe96f276913af0572475e@gmail.com>
In reply to#111735
On Wed, 7 Jun 2017 10:17:58 -0700 (PDT)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:

> Just the first one.  I want to know how many of a thing there are in
> a row, and only in that single run / sequence.  It's why I called it
> mem[scan] ... it's scanning forward for that matching character in
> repetition until the count is exhausted or it's no longer found.

const char s[7] = "$$$$hi";

/* locate the first '$' occurence */
const char *s0 = strchr(s, '$');

/* compute the longest initial segment with only '$' */ 
size_t n = strspn(s0, "$");

I believe this could be enough and give n = 4 as expected.

[toc] | [prev] | [next] | [standalone]


Page 1 of 7  [1] 2 3 4 5 6 7  Next page →

Back to top | Article view | comp.lang.c


csiph-web