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