Skip to content

Commit

Permalink
menu
Browse files Browse the repository at this point in the history
  • Loading branch information
amelie-certin committed Dec 14, 2016
1 parent eea19f5 commit 11b0563
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
71 changes: 71 additions & 0 deletions src/gestorth.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,76 @@
#include "gestorth.h"

/**
* \brief Function for guide user into the third main menu
*/
void main3Menu(void) {
int choice;
do {
printf("\n\n*** Dictionaries management ***\n\n"
"\t1. Open an existing dictionary\n"
"\t0. Quit\n\n");
do {
printf("Your choice: ");
} while(!getIntRange(&choice, 0, 1));
switch (choice) {
case 1:
menu3OpenDictionary();
break;
case 0:
printf("Good bye!\n");
break;
}
} while(choice != 0);
}

/**
* \brief Function for guide user into the third menu
*/
void menu3(Dictionary *dico) {
int choice;
do {
printf("\n\n--- Dictionary %s ---\n\n"
"\t1. Find unknown words\n"
"\t2. Suggest a correction for unknown words\n"
"\t3. Auto correct a text file\n"
"\t0. Return to Dictionaries management\n\n", dico->filename);
do {
printf("Your choice: ");
} while(!getIntRange(&choice, 0, 3));
char *filename = malloc(sizeof(char) * 255);
printf("Please tape the path to your txt file: ");
getString(255, filename);
switch (choice) {
case 1:
listMissingWords(dico, filename);
break;
case 2:
suggestSimilarWords(dico, filename);
break;
case 3:
autoCorrectFile(dico, filename);
break;
case 0:
freeDictionary(dico);
clear();
break;
}
free(filename);
} while(choice != 0);
}

/**
* \brief Help the user to open a Dictionary
*/
void menu3OpenDictionary(void) {
char *dico = menuSelectDictionary();
if(dico != NULL) {
menu3(selectDictionary(dico));
free(dico);
dico = NULL;
}
}

/**
* \param dico The dictionary who contains words
* \param filename The name of the file who contain the text
Expand Down
4 changes: 4 additions & 0 deletions src/gestorth.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "linked_words.h"
#include <ctype.h>

void main3Menu(void);
void menu3(Dictionary *dico);
void menu3OpenDictionary(void);

void searchMissingWords(Dictionary *dico, const char *filename, int code);
void listMissingWords(Dictionary *dico, const char *filename);
void suggestSimilarWords(Dictionary *dico, const char *filename);
Expand Down
6 changes: 2 additions & 4 deletions src/main3.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "gestorth.h"

int main(void) {
// Should use the menu3 method
Dictionary *dico = selectDictionary("demo");
listMissingWords(dico, "yolo.txt");
freeDictionary(dico);
clear();
main3Menu();
return 0;
}

0 comments on commit 11b0563

Please sign in to comment.