diff options
Diffstat (limited to 'session.c')
-rw-r--r-- | session.c | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -8,15 +8,25 @@ void startSession(FILE *dictionary) if ( dictionary != NULL ) { int totalWords = lineCounter(dictionary); - char *word; + char *word, *question = (char *) calloc(MAX_LINE, sizeof(char));; char reload = '\0'; - while( reload != 'q' ) + printf("WELCOME\n" + "Type GOODBYE to exit\n\n"); + + while( strcmp(question, "GOODBYE\n") != 0 ) { - word = getLine(dictionary, getRandomNumber(1, totalWords)); - printf("%s", word); - free(word); - reload = getchar(); + printf("Enter a question: "); + fgets(question, MAX_LINE, stdin); + + if ( strcmp(question, "GOODBYE\n") != 0 ) + { + word = getLine(dictionary, getRandomNumber(1, totalWords, question)); + printf("-> %s", word); + free(word); + } } + + free(question); } } |