Aug 8, 2008

Partial String Matching

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

free web hosting

Partial String Matching

kvarnerexpress
Im trying to search a linked list to delete a record which is in a file that works. But im now trying to match only part of the string partial string matching.

Im using strstr but i cant seem to get it working i get too few arguments error. And i also would like to know if im on the right track as to how im coding it. Any hints and tips would be greatly appreciated thanks.

Code:
CODE

/****************************************************************************
* Menu option #3: Delete Record
* Allows the user to remove one or more records from the customer and/or
* stock linked lists. Partial string matching is implemented.
****************************************************************************/
void deleteRecord(TennisStoreType* ts)
{

 StockNodeType* curStock;
 StockNodeType* prevStock;
 CustomerNodeType*  curCust;
 CustomerNodeType*  prevCust;

 char inputString[DESCRIPTION_MAX + 1];
 char *description;
 char tmpsurname[SURNAME_MAX];
 char *surname;
 char answerInput;
 char *firstName;
 char *subDesc;

 int finished;
   
 do
 {    
 printf("\n\nInput String (1-40 characters) ");
   
 fgets(inputString, DESCRIPTION_MAX +2 , stdin);

 /* check if the input is longer then the buffer (40 chars)
    Validating input of 40 characters for string*/

 if(inputString[strlen(inputString) -1] != '\n')
 {
      printf("\nProduct description too delete less then 40 chars!\n");
      readRestOfLine();
      /* flush the buffer */
 }
 if(inputString[0] == '\n')
 {
   printf("Returning back to main menu\n");
   finished = FAILURE;

 }

}while(inputString[strlen(inputString) -1 ] != '\n');

 /* tokenize the data fields to be searched*/    
 description = strtok(inputString, "\n");
 surname = strtok(inputString, "\n");  
 firstName = strtok(inputString, "\n");

   

 curStock = ts -> headStock;
 prevStock = NULL;

 curCust = ts -> headCust;
 prevCust = NULL;
   
 printf("Are you sure you want to delete\n");    

 do
 {
     answerInput = fgetc(stdin);

     if(answerInput == 'y')
     {
       printf("you pressed yes!\n");
     }
     else if(answerInput == 'n')
     {

       printf("You pressed no!\n");
       return;
       
     }

 } while (answerInput != '\n');

 strcpy(inputString, subDesc);
 
 if(subDesc = strstr(("Slazenger Classic Racquet"),
   ("Slazenger")) != NULL)
 {
    printf("found a match %s", inputString);
 }
 else
 {
    printf("no match!");
 }
 
 
 while((curStock != NULL) && ((curCust != NULL) &&

      strcmp(inputString,curStock->description) &&
      strcmp(inputString, curCust -> surname) &&
      strcmp(inputString, curCust -> firstName)!= MIN_INPUT))
 {
      prevStock = curStock;
      curStock = curStock->nextStock;

      /* searching through the customer nodes
      if not null keep getting the next node
      for searching*/

      prevCust = curCust;
      curCust = curCust -> nextCust;


 }

 
   

 if ((curStock == NULL)  || (curCust == NULL))
 {
      printf("This item is not listed! \"%s\" .\n",
            inputString);

      printf("Try again\n");

      return;
 }
 else if ((prevStock == NULL) || (prevCust == NULL))
 {

     
        ts->headStock = curStock->nextStock;
        ts->headCust  = curCust -> nextCust;
 }
 else
 {
        prevStock->nextStock = curStock->nextStock;
        prevCust ->nextCust = curCust -> nextCust;
 }      
 
        ts-> stockCount --;
        ts-> customerCount--;

        printf("\nTotal stock or customer after deletion: %d\n"
               , ts -> stockCount);

        printf("%s", inputString);
       
   
   


}


Thanks,kvarnerexpress

 

 

 


Reply

dexter
The problem is the way you constructed your if statement.

This:
CODE

// The parentheses are not needed around the strings.  
// They do nothing, nor even make it more readable.
if(subDesc = strstr("Slazenger Classic Racquet",
 "Slazenger") != NULL)


Is exactly the same as saying:

CODE

if(subDesc = (strstr("Slazenger Classic Racquet",
 "Slazenger") != NULL))


Currently it is trying to assign to subDesc whether or not the return of strstr is equal to NULL. This doesn't fly. This is because assignments have the last priority.

A correct way of constructing that assignment would be:

CODE

if((subDesc = strstr("Slazenger Classic Racquet",
 "Slazenger")) != NULL)


Whenever you use assignment in an if statement -always- wrap the assignment part in parentheses before doing the comparison.

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : partial matching


    Looking for partial, string, matching

Searching Video's for partial, string, matching
advertisement



Partial String Matching



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE