summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ouija.c2
-rw-r--r--session.c10
-rw-r--r--utils.c4
3 files changed, 8 insertions, 8 deletions
diff --git a/ouija.c b/ouija.c
index 96221db..44e6cc9 100644
--- a/ouija.c
+++ b/ouija.c
@@ -16,7 +16,7 @@ int main(int argc, char **argv)
}
break;
case 2:
- if (checkIfFileExists(argv[1]) == 1)
+ if (checkIfFileExists(argv[1]) == 0)
{
dictionary = fopen(argv[1], "r");
}
diff --git a/session.c b/session.c
index 0b0c11d..b04958d 100644
--- a/session.c
+++ b/session.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "session.h"
void startSession(FILE *dictionary)
@@ -7,16 +8,15 @@ void startSession(FILE *dictionary)
if ( dictionary != NULL )
{
int totalWords = lineCounter(dictionary);
- char* word = (char *) calloc(256, sizeof(char));
- char reload;
+ char *word;
+ char reload = '\0';
while( reload != 'q' )
{
word = getLine(dictionary, getRandomNumber(1, totalWords));
- printf("%s\n", word);
+ printf("%s", word);
free(word);
- //reload = getchar();
- //getchar();
+ reload = getchar();
}
}
}
diff --git a/utils.c b/utils.c
index 4a2b4ce..54800bc 100644
--- a/utils.c
+++ b/utils.c
@@ -15,9 +15,10 @@ int lineCounter(FILE *dictionary)
if ( dictionary != NULL )
{
char line[MAX_LINE];
- for( words; (!feof(dictionary)); words++ )
+ for( int i = words; (!feof(dictionary)); i++ )
{
fgets(line, MAX_LINE, dictionary);
+ words = i;
}
rewind(dictionary);
words--;
@@ -41,6 +42,5 @@ char* getLine(FILE *dictionary, int lineNumber)
int getRandomNumber(int min, int max)
{
- srand(time(0));
return ((rand() % (max - min + 1)) + 1);
}