From 9926c34b380ae7adf4507b89b39450eba26bac61 Mon Sep 17 00:00:00 2001 From: Aidan Haas <94150901+ahaas25@users.noreply.github.com> Date: Mon, 7 Nov 2022 18:35:45 -0500 Subject: [PATCH] Add makefile --- debugger.c | 3 ++- typing_test.c | 32 +------------------------------- typing_test.h | 7 +------ utilities.c | 32 ++++++++++++++++++++++++++++++++ utilities.h | 14 ++++++++++++++ 5 files changed, 50 insertions(+), 38 deletions(-) create mode 100644 utilities.c create mode 100644 utilities.h diff --git a/debugger.c b/debugger.c index ea40f4d..0b9f650 100644 --- a/debugger.c +++ b/debugger.c @@ -3,6 +3,7 @@ #include #include #include +#include "utilities.h" #include "typing_test.h" int main() { @@ -10,5 +11,5 @@ int main() { words = fopen("words.txt", "r"); Word_array word_array; - parse_words_file(words, word_array); + parse_words_file(words, &word_array); } \ No newline at end of file diff --git a/typing_test.c b/typing_test.c index 036a4a5..8a29a3a 100644 --- a/typing_test.c +++ b/typing_test.c @@ -4,6 +4,7 @@ #include #include #include "typing_test.h" +#include "utilities.h" /* Prints Centered Text To Console Screen */ void print_centered_text(WINDOW *win, int row, char str[]) { @@ -43,37 +44,6 @@ void print_centered_text_menu(WINDOW *win, int row, int target, char str[][MAX_S } } -/* This will go through the word_array structure and find the requested - amount of words */ -int generate_words(int num_words, Word_array *words, char *to_return) { - int i, k, number_words_in_txt; - - to_return = malloc(num_words * 64); /* Each word will be less than 64 chars */ - - for (i = 0; i < words->number_of_words; i++) { - - } - - return SUCCESS; -} - - -/* This will dynamically allocate memory to a 2d char array of all the words - in words.txt */ -int parse_words_file(FILE *words_file, Word_array *words) { - int i, number_of_words; - char buf[256]; - - /* Counts number of lines in words file (Each line contains a unique word) */ - while (fgets(buf, sizeof(buf), words) != NULL) { - number_of_words++; - } - - printf("Number of words: %d\n", number_of_words); - - return SUCCESS; -} - void typing_ui(WINDOW *win, int level, int mode, FILE *word_file) { int run = 1, ch, i, words, win_x = win->_maxx; char str[1024]; diff --git a/typing_test.h b/typing_test.h index 1cf69d7..178e470 100644 --- a/typing_test.h +++ b/typing_test.h @@ -8,9 +8,4 @@ #define FAILURE 0 char TIMED_MODES_STRING[5][MAX_STRING] = { "5s", "10s", "25s", "30s", "60s" }; char WORD_MODES_STRING[5][MAX_STRING] = { "10", "25", "50", "100", "200" }; -char MISC_STRING[3][MAX_STRING] = {"Exit", "Stats", "Settings"}; - -typedef struct { - int number_of_words; - char words[]; -} Word_array; \ No newline at end of file +char MISC_STRING[3][MAX_STRING] = {"Exit", "Stats", "Settings"}; \ No newline at end of file diff --git a/utilities.c b/utilities.c new file mode 100644 index 0000000..a229ad0 --- /dev/null +++ b/utilities.c @@ -0,0 +1,32 @@ +#include "utilities.h" + +/* This will go through the word_array structure and find the requested + amount of words */ +int generate_words(int num_words, Word_array *words, char *to_return) { + int i, k, number_words_in_txt; + + to_return = malloc(num_words * 64); /* Each word will be less than 64 chars */ + + for (i = 0; i < words->number_of_words; i++) { + + } + + return SUCCESS; +} + + +/* This will dynamically allocate memory to a 2d char array of all the words + in words.txt */ +int parse_words_file(FILE *words_file, Word_array *words) { + int i, number_of_words = 0; + char buf[256]; + + /* Counts number of lines in words file (Each line contains a unique word) */ + while (fgets(buf, sizeof(buf), words_file) != NULL) { + number_of_words++; + } + + printf("Number of words: %d\n", number_of_words); + + return SUCCESS; +} \ No newline at end of file diff --git a/utilities.h b/utilities.h new file mode 100644 index 0000000..b87227b --- /dev/null +++ b/utilities.h @@ -0,0 +1,14 @@ +#include +#include +#include + +#define SUCCESS 1 +#define FAILURE 0 + +typedef struct { + int number_of_words; + char words[]; +} Word_array; + +int generate_words(int num_words, Word_array *words, char *to_return); +int parse_words_file(FILE *words_file, Word_array *words); \ No newline at end of file