I am using strstr to do a partial string match on a linked list. Problem is it is return the opposite of what i want.
say i have various words to compare. These include
disposed
dispose
is
if i search for "dispose"
it returns
dispose
is
if i search for "disposed"
it returns
disposed
dispose
is
if i search for "is"
it returns
is
But i want it to do the opposite. If i search for "is" i want is, dispose and disposed.
Any ideas?
Code:
/* Structure definitions. */
typedef struct wordStruct* WordTypePtr;
typedef struct wordStruct
{
char* word;
unsigned count;
WordTypePtr nextWord;
} WordType;
typedef struct indexStruct
{
WordTypePtr headWord;
WordTypePtr longestWord;
WordTypePtr mostCommonWord;
unsigned totalWords;
unsigned uniqueWords;
} IndexType;
Code:
IndexType index;
searchIndex(&index);
Code:
00000001 void searchIndex(IndexType* index)
00000002 {
00000003 char *myString[MAX_SIZE+2];
00000004 printf("\nIndex Search\n");
00000005 printf("------------\n");
00000006 printf("\nEnter a word:");
00000007 fgets(*myString, MAX_SIZE+2, stdin);
00000008
00000009
00000010 WordType *root,*conductor;
00000011 root = (WordType *)malloc(sizeof(WordType));
00000012 root->nextWord=index->headWord;
00000013 root->word=NULL;
00000014
00000015 conductor=root;
00000016
00000017 conductor = conductor->nextWord;
00000018 if ( conductor != 0 ) {
00000019 while ( conductor->nextWord != 0 ) {
00000020 if (conductor->word!=NULL){
00000021 /*printf ("Returned String 1: %s\n", strstr (*myString, conductor->word));
00000022 if (strstr (*myString, conductor->word)==NULL){*/
00000023 if (strstr (*myString,conductor->word)==NULL){
00000024 }else{
00000025 printf(conductor->word);
00000026 printf ("\t(%d)\n", conductor->count);
00000027 }
00000028 }
00000029 conductor = conductor->nextWord;
00000030 }
00000031
00000032 }
00000033
Hope my code is cleaner this time