Thread: partial string matchin strstr

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    partial string matchin strstr

    Hey guys im trying to use strstr to implement the partial string search. Im actually searching through a file using a linked list and trying to match "Slazenger" and make it find
    Slazenger Classic Racquet


    Code:
    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);
             
        
         
    
    
    }

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    So ? What's the problem ?
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252
    Well im getting a warning saying few too arguments and i am not sure as to if im doing the partial matching correctly.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Too few arguments on which line? Calling which function?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM