[Coco] "C string searching question

Steve 6809er at srbsoftware.com
Tue Oct 2 00:10:59 EDT 2012


Maybe you should try a tokenizing search?  Start with creating a list of 
tokens for all the "words" in the song titles. (This table is updated 
only when a new song is added to the database.)  Don't forget to save 
the title as a list of tokens too.

When a user give you titles to search for,  you need to convert it into 
a token list based on the token database of all the song titles.  Any 
search words not in the token list should be dropped.

Now do a token list to token list search.  (Comparing the shorter token 
list is a lot faster then doing a string search over and over.)

Oh, don't forget to change the letters to the same case and convert any 
non-alphanumeric to spaces before tokenizing.

You will find this type of search is much faster and easier since most 
of the work is done when creating the token database.


On 10/1/2012 8:15 PM, Bill Pierce wrote:
> Here's a "C" programming question for you "C" gurus out there
>
> I'm writing a search routine for SoundChaser's 500 song database.
> here's the data format:
>
> #define NRECORDS 500   /* max num of records */
> #define RECNAMEL  33    /* size of record name */
>
> typedef struct{
>     char recname[RECNAMEL];   /* song name */
>     char ext[4];    /* filename extension */
>     int typ;     /* song type (midi mus ect ) */
>     int order;   /* selection order */
>     bool played   /* has played flag */
> } Record;
>
>
> direct short nrecords;  /* actual number of records */
> Record records[ ];   /* the record keeper */
> char srchstr[10];  /* the search string
>
> ok, here's the loop:
>
> loop to input srchstr[xx] here
>
> for(cnt=0; cnt<=nrecords; cnt++) {
>     for(xx=0; xx<=sizeof(srchstr); xx++){
>        if(srchstr[xx] == records[cnt].recname[xx]) {
>            search some stuff here..
>            then search some more stuff
>        }
>     }
> }
>
> what should I do in the loop or is there a better looping routine I can use to find the matching string.
> The record will be searched for the matching sting anywhere in the record i.e.   search for rock;  likearock; rocknroll; iluvrocknroll;
> what would be the best way to do this efficiantly?
> the result has to point to cnt as that will be the index to the record found.
>
> any ideas? (I just love cans of worms)
> Bill P
> Music from the Tandy/Radio Shack Color Computer 2 & 3
>
> https://sites.google.com/site/dabarnstudio/
> Bill Pierce
> ooogalapasooo at aol.com
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco




More information about the Coco mailing list