From 009c0b27733fa67db018d3ea65df3ace229562fa Mon Sep 17 00:00:00 2001 From: rafa_99 Date: Sat, 2 Jan 2021 18:33:35 +0000 Subject: Updated Clang Format Style --- ouija.c | 21 +++++++++++---------- session.c | 30 ++++++++++++++++-------------- session.h | 2 +- utils.c | 47 ++++++++++++++++++++++++++--------------------- utils.h | 10 +++++----- 5 files changed, 59 insertions(+), 51 deletions(-) diff --git a/ouija.c b/ouija.c index c55737f..5b90cdf 100644 --- a/ouija.c +++ b/ouija.c @@ -1,9 +1,10 @@ -#include -#include #include "session.h" #include "utils.h" +#include +#include -int main(int argc, char **argv) +int +main (int argc, char **argv) { FILE *dictionary = NULL; @@ -11,26 +12,26 @@ int main(int argc, char **argv) switch (argc) { case 1: - if (checkIfFileExists("dictionary.dict") == 0) + if (checkIfFileExists ("dictionary.dict") == 0) { - dictionary = fopen("dictionary.dict", "r"); + dictionary = fopen ("dictionary.dict", "r"); } break; case 2: - if (checkIfFileExists(argv[1]) == 0) + if (checkIfFileExists (argv[1]) == 0) { - dictionary = fopen(argv[1], "r"); + dictionary = fopen (argv[1], "r"); } } if (dictionary != NULL) { - startSession(dictionary); - fclose(dictionary); + startSession (dictionary); + fclose (dictionary); } else { - printf("No Dictionary Found\n"); + printf ("No Dictionary Found\n"); } return 0; diff --git a/session.c b/session.c index e3b8702..2991469 100644 --- a/session.c +++ b/session.c @@ -1,32 +1,34 @@ +#include "utils.h" #include #include #include -#include "utils.h" -void startSession(FILE *dictionary) +void +startSession (FILE *dictionary) { - if ( dictionary != NULL ) + if (dictionary != NULL) { - int totalWords = lineCounter(dictionary); - char *word, *question = (char *) calloc(MAX_LINE, sizeof(char));; + int totalWords = lineCounter (dictionary); + char *word, *question = (char *)calloc (MAX_LINE, sizeof (char)); char reload = '\0'; - printf("WELCOME\n" + printf ("WELCOME\n" "Type GOODBYE to exit\n\n"); - while( strcmp(question, "GOODBYE\n") != 0 ) + while (strcmp (question, "GOODBYE\n") != 0) { - printf("Enter a question: "); - fgets(question, MAX_LINE, stdin); + printf ("Enter a question: "); + fgets (question, MAX_LINE, stdin); - if ( strcmp(question, "GOODBYE\n") != 0 ) + if (strcmp (question, "GOODBYE\n") != 0) { - word = getLine(dictionary, getRandomNumber(1, totalWords, question)); - printf("-> %s", word); - free(word); + word = getLine (dictionary, + getRandomNumber (1, totalWords, question)); + printf ("-> %s", word); + free (word); } } - free(question); + free (question); } } diff --git a/session.h b/session.h index 989fd65..283e429 100644 --- a/session.h +++ b/session.h @@ -1,4 +1,4 @@ #include /* Starts a oujia session using a inputted dictionary file */ -void startSession(FILE *dictionary); +void startSession (FILE *dictionary); diff --git a/utils.c b/utils.c index 83bfdd2..057f6ef 100644 --- a/utils.c +++ b/utils.c @@ -1,62 +1,67 @@ +#include "utils.h" #include #include #include +#include #include #include -#include -#include "utils.h" -int checkIfFileExists(char *path) +int +checkIfFileExists (char *path) { - return access(path, F_OK); + return access (path, F_OK); } -int numerize(char *string) +int +numerize (char *string) { int val = 0; - for( int i = 0; i < strlen(string); i++ ) + for (int i = 0; i < strlen (string); i++) { val += string[i]; } return val; } -int lineCounter(FILE *dictionary) +int +lineCounter (FILE *dictionary) { int words = 0; - if ( dictionary != NULL ) + if (dictionary != NULL) { char line[MAX_LINE]; - for( int i = words; (!feof(dictionary)); i++ ) + for (int i = words; (!feof (dictionary)); i++) { - fgets(line, MAX_LINE, dictionary); + fgets (line, MAX_LINE, dictionary); words = i; } - rewind(dictionary); + rewind (dictionary); words--; } return words; } -char* getLine(FILE *dictionary, int lineNumber) +char * +getLine (FILE *dictionary, int lineNumber) { - char *line = (char *) calloc(MAX_LINE, sizeof(char)); - if ( dictionary != NULL ) + char *line = (char *)calloc (MAX_LINE, sizeof (char)); + if (dictionary != NULL) { - for ( int i = 0; (!feof(dictionary) && i != lineNumber ); i++) + for (int i = 0; (!feof (dictionary) && i != lineNumber); i++) { - fgets(line, MAX_LINE, dictionary); + fgets (line, MAX_LINE, dictionary); } - rewind(dictionary); + rewind (dictionary); } return line; } -int getRandomNumber(int min, int max, char *question) +int +getRandomNumber (int min, int max, char *question) { struct timespec s; - clock_gettime(CLOCK_REALTIME, &s); - srand(s.tv_nsec * numerize(question)); + clock_gettime (CLOCK_REALTIME, &s); + srand (s.tv_nsec * numerize (question)); - return ((rand() % (max - min + 1)) + min); + return ((rand () % (max - min + 1)) + min); } diff --git a/utils.h b/utils.h index 0903c86..5ccabe3 100644 --- a/utils.h +++ b/utils.h @@ -3,17 +3,17 @@ #define MAX_LINE 256 /* Checks if a file exists */ -int checkIfFileExists(char *path); +int checkIfFileExists (char *path); /* Turns a string into a number by * using the sum of its ascii values. */ -int numerize(char *string); +int numerize (char *string); /* Counts the lines from a dictionary file */ -int lineCounter(FILE *dictionary); +int lineCounter (FILE *dictionary); /* Returns a specified line from a dictionary file */ -char* getLine(FILE *dictionary, int line); +char *getLine (FILE *dictionary, int line); /* Returns a random number within the inclusive number range * and based on the inputted question. * Uses a fast seeded number generator. */ -int getRandomNumber(int min, int max, char *question); +int getRandomNumber (int min, int max, char *question); -- cgit v1.2.3