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
Post a Comment