[Coco] "C string searching question
Retro Canada
retrocanada76 at gmail.com
Tue Oct 2 13:20:34 EDT 2012
no, it should be this:
for(cnt = 0; cnt <= nrecords; ct++) {
result=(strstr(records[cnt].recname, srchstr);
if(result)
goto match
}
On Tue, Oct 2, 2012 at 12:56 PM, Bill Pierce <ooogalapasooo at aol.com> wrote:
>
> Thanks, I'll give it a try and see if it dos what I need. With the search being "in memoy" it should take too long. The whole problem is that it needs to step through the target to find an occurance. It's an easy task to get the string from the front of the target, but not from within. I assume from your code that I can:
>
> for(cnt = 0; cnt <= nrecords; ct++) {
> result=(strstr(records[cnt].recname, srchstr);
> if(result == srchstr)
> goto match
> }
>
> Would that work with your code?
>
> Bill P
>
> Music from the Tandy/Radio Shack Color Computer 2 & 3
> https://sites.google.com/site/dabarnstudio/
> Bill Pierce
> ooogalapasooo at aol.com
>
>
>
>
> -----Original Message-----
> From: Retro Canada <retrocanada76 at gmail.com>
> To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
> Sent: Tue, Oct 2, 2012 7:59 am
> Subject: Re: [Coco] "C string searching question
>
>
> Then strstr is what you need. If you don't have it you MAKE it :)
>
>
> const char * strstr (
> const char * str1,
> const char * str2
> )
> {
> const char * cp = str1;
> const char * s1;
> const char * s2;
>
> if ( !*str2 )
> return str1;
>
> while (*cp)
> {
> s1 = cp;
> s2 = str2;
>
> while ( *s1 && *s2 && !(*s1-*s2) )
> s1++, s2++;
>
> if (!*s2)
> return( (char*)cp );
>
> cp++;
> }
>
> return 0 ;
> }
>
>
>
> On Tue, Oct 2, 2012 at 7:33 AM, Bill Pierce <ooogalapasooo at aol.com> wrote:
>>
>> strcmp would work, but it would only do n chars from the start... I need to
> step through a 33 char name and find a 10 char string. s1=catanddog; s2=dog;
> n=3; strcmp(s1, s2, n) will not find dog, it will see cat.
>> What's needed is a function with a start point. Using the above example:
>>
>> for(c=0; c<=sizeof(s1); c++);
>> srchstr=(srchfunc(s1, s2, c, n)) {
>> if(srcgfunc == s2)
>> goto match
>> }
>>
>> Bill P
>>
>> Music from the Tandy/Radio Shack Color Computer 2 & 3
>> https://sites.google.com/site/dabarnstudio/
>> Bill Pierce
>> ooogalapasooo at aol.com
>>
>>
>>
>>
>> -----Original Message-----
>> From: Retro Canada <retrocanada76 at gmail.com>
>> To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
>> Cc: coco <coco at maltedmedia.com>
>> Sent: Tue, Oct 2, 2012 7:18 am
>> Subject: Re: [Coco] "C string searching question
>>
>>
>> then use strncmp
>>
>> Sent from my iPhone
>>
>> On 2012-10-02, at 4:19 AM, Bill Pierce <ooogalapasooo at aol.com> wrote:
>>
>>>
>>> The files will be on whoever's computer they are on as this is a publicly
>> available program, so no guarantee of any sort what-so-ever.
>>>
>>> I'm probably going to use a 10 character search string as most things people
>> would search for wouldn't have much more, though the titles can be up to 33
>> characters. So the search has to look through all 33 chars of 500 strings for
> a
>> match of 10 chars at the most, but could be less according to what the user
>> specifies in the search, so the size of the searcg string will be variable.
>>>
>>> All I want to do is search throuh a list of strings and find ONE occurance of
>> the search string, this can be anywhere in the string being searched, not just
>> at the beginning, then if that ocurrance is not the right one, it will be
>> discarded and the next occurance will be searched. No catalogging is done and
>> nothing is saved.
>>>
>>> One thing I've failed to mention... all the strings are in memory. There will
>> be no disk activity, only memory reads. The file directory is read when the
>> directory is chosen and the strings are initiated then. The user will search
> at
>> any given time, for any given string. The directories can be changed at any
> time
>> so no sort of sort, token or database can be created as the next time more
> songs
>> may have been thrown into the directory since the last.. It has to be a
> realtime
>> search.
>>>
>>> To see what I'm trying to search, just download the Sound Chaser Beta from my
>> links and intall the programs the the music dirs from the 2nd & 3rd disks (all
>> music into one dir). Then run the program and you'll see what the list is.
>>> Please read the docs before installing or running as there's a lot to this
>> program thought it's pretty straight forward.
>>>
>>>
>>> Bill P
>>>
>>>
>>> Music from the Tandy/Radio Shack Color Computer 2 & 3
>>> https://sites.google.com/site/dabarnstudio/
>>> Bill Pierce
>>> ooogalapasooo at aol.com
>>>
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: John Kent <jekent at optusnet.com.au>
>>> To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
>>> Sent: Tue, Oct 2, 2012 3:35 am
>>> Subject: Re: [Coco] "C string searching question
>>>
>>>
>>>
>>> If the records are ordered alphabetically based on the record name and
>>> the search strings are sorted alphabetical you could do a sort of merge
>>> search.
>>> i.e. Once you match the first string you can work from that point in
>>> each list to match the next string.
>>> The near optimal sort is a Batcher sort although it's a trade off
>>> between speed and memory space.
>>> You can do a recursive successive approximation sort, or an insertion
>>> sort if you are building the search list entry by entry.
>>> You could use a linked list or double linked list, so you only have to
>>> move the pointers rather than the whole record.
>>> There is a Sort and Merge package for Flex9 for the 6809.
>>> Google for sorting and searching algorithms.
>>>
>>> John.
>>>
>>> On 2/10/2012 3:22 PM, Bill Pierce wrote:
>>>> This is why I was doing byte by byte search... find fist char, then match
>> 2nd,
>>> ?no match? move to next char in string and start over. I had it working just
>>> doing first word search, then started editing the code to move through the
>>> string for any occurance and got it messed up. Now I can't seem to get it
> back
>>
>>> to the working version... and by the way, it was pretty fast through almost
>> 200
>>> songs. I didn't try any higher counts yet.
>>>>
>>>> Bill P
>>>>
>>>> Music from the Tandy/Radio Shack Color Computer 2 & 3
>>>> https://sites.google.com/site/dabarnstudio/
>>>> Bill Pierce
>>>> ooogalapasooo at aol.com
>>>>
>>>>
>>>
>>> --
>>> http://www.johnkent.com.au
>>> http://members.optusnet.com.au/jekent
>>>
>>>
>>>
>>> --
>>> Coco mailing list
>>> Coco at maltedmedia.com
>>> http://five.pairlist.net/mailman/listinfo/coco
>>>
>>>
>>>
>>> --
>>> Coco mailing list
>>> Coco at maltedmedia.com
>>> http://five.pairlist.net/mailman/listinfo/coco
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> http://five.pairlist.net/mailman/listinfo/coco
>>
>>
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> http://five.pairlist.net/mailman/listinfo/coco
>
>
>
> --
> Panasonic FSA1-WSX
> Commodore 64
> Commodore 64C
> Commodore 128
> Apple //c
> TRS-Color Computer 3
> TI-99/4A
> ..and more coming!
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
--
Panasonic FSA1-WSX
Commodore 64
Commodore 64C
Commodore 128
Apple //c
TRS-Color Computer 3
TI-99/4A
..and more coming!
More information about the Coco
mailing list