c - Searchin in a stack -


this code searching part , it's not working. can give me little on this? i'm newbie on programming , suck @ pointers. thanks.

typedef struct dictionary_entry{     int index;     char character[100];     struct dictionary_entry *link; }dictionary_entry;  typedef struct dictionary{     dictionary_entry *top; }dictionary;  int check_in_dictionary(dictionary *dictionary, char string[100], char file_char[100]){     dictionary_entry *runner = dictionary->top;     strcat(string, file_char);         while(runner != null){             if((strcmp(string, runner->character)) == 0){                 break;                 return runner->index;             }         }         return -1; } 

here corrected version comments starting ////

int check_in_dictionary(dictionary *dictionary, char string[100], char file_char[100]){     dictionary_entry *runner = dictionary->top;     strcat(string, file_char);     while(runner != null){       if((strcmp(string, runner->character)) == 0){          return runner->index;  // found          //// break not neccessary here return returns anyway       }       runner = runner->link ;  //// goto next entry     }     return -1; } 

btw strcat(string, file_char); not necessary, compare directy file_char strcmp(file_char, runner->character)


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -