From 7be4deeee60d11e3ae09ddef1147b2a93b183d88 Mon Sep 17 00:00:00 2001 From: rafa_99 Date: Fri, 4 Dec 2020 03:31:45 +0000 Subject: Pushed Working Board --- Makefile | 15 ++++++++++----- README.md | 23 +++++++++++++++++++++++ images/image.png | Bin 0 -> 4185545 bytes logo.png | Bin 0 -> 37120 bytes ouija.c | 6 +++++- session.c | 22 ++++++++++++++++------ utils.c | 17 ++++++++++++++--- utils.h | 3 ++- 8 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 images/image.png create mode 100644 logo.png diff --git a/Makefile b/Makefile index f22e98e..744a229 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,13 @@ build: clean - gcc -o ouija ouija.c session.c utils.c - -debug: clean - gcc -g -o ouija ouija.c session.c utils.c + cc -o ouija ouija.c session.c utils.c clean: - rm -rf ouija + rm -rf ouija + +install: build + mkdir -p /usr/local/bin + cp -f ouija /usr/local/bin + chmod 755 /usr/local/bin + +uninstall: + rm -rf /usr/local/bin/ouija diff --git a/README.md b/README.md index d564471..2f5cdb8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,25 @@ # Ouija Board +Just a ouija board based on time and question randomness +## Inspiration +Inspired by Terry Davis TempleOS Timer Random Tongues which he used to communicate with God. + +Since TRT was written in HolyC and this random word generator is written in C I decided to call it a Ouija Board. + +![TempleOS Timer Random Tongues](images/image.png) + +## How to Use + +### Compile +#### Portable +`make` + +#### Installable +`make install` + +### Run +If you already have a `dictionary.dict` file in your path, just run: +`ouija` + +If you have the file saved in another folder, just type: +`ouija /path/to/dictionary` diff --git a/images/image.png b/images/image.png new file mode 100644 index 0000000..34e58e0 Binary files /dev/null and b/images/image.png differ diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..8681e3b Binary files /dev/null and b/logo.png differ diff --git a/ouija.c b/ouija.c index 44e6cc9..aab31c5 100644 --- a/ouija.c +++ b/ouija.c @@ -1,6 +1,6 @@ -#include "session.h" #include #include +#include "session.h" int main(int argc, char **argv) { @@ -27,6 +27,10 @@ int main(int argc, char **argv) startSession(dictionary); fclose(dictionary); } + else + { + printf("No Dictionary Found\n"); + } return 0; } diff --git a/session.c b/session.c index b04958d..205e92f 100644 --- a/session.c +++ b/session.c @@ -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); } } diff --git a/utils.c b/utils.c index 49a6069..e349368 100644 --- a/utils.c +++ b/utils.c @@ -1,7 +1,8 @@ #include -#include #include +#include #include +#include #include #include "utils.h" @@ -10,6 +11,16 @@ int checkIfFileExists(char *path) return access(path, F_OK); } +int numerize(char *string) +{ + int val = 0; + for( int i = 0; i < strlen(string); i++ ) + { + val += string[i]; + } + return val; +} + int lineCounter(FILE *dictionary) { int words = 0; @@ -41,12 +52,12 @@ char* getLine(FILE *dictionary, int lineNumber) return line; } -int getRandomNumber(int min, int max) +int getRandomNumber(int min, int max, char *question) { // Adding Randomize Time Values for Less Chances of Running into Seed Collisions struct timeval randtime; gettimeofday(&randtime,NULL); - srand((randtime.tv_sec * 100 + time(NULL)) + (randtime.tv_usec / 100 - time(NULL))); + srand(((randtime.tv_sec * 100) + time(NULL) * numerize(question)) + ((randtime.tv_usec / 100) - time(NULL) * numerize(question))); return ((rand() % (max - min + 1)) + 1); } diff --git a/utils.h b/utils.h index 0b72df4..6cfbc80 100644 --- a/utils.h +++ b/utils.h @@ -3,6 +3,7 @@ #define MAX_LINE 256 int checkIfFileExists(char *path); +int numerize(char *string); int lineCounter(FILE *dictionary); char* getLine(FILE *dictionary, int line); -int getRandomNumber(int min, int max); +int getRandomNumber(int min, int max, char *question); -- cgit v1.2.3