-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.c
81 lines (74 loc) · 2.07 KB
/
reader.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "reader.h"
void count_users(void) {
FILE *fp;
char line[500];
fp = fopen("Authentication.txt", "r");
if (fp == NULL) {
printf("Couldn't open file\n");
exit(-1);
}
while(fgets(line, sizeof(line), fp) != NULL) user_count++;
--user_count;
fclose(fp);
}
void count_combinations(void) {
FILE *fp;
char line[500];
fp = fopen("hangman_text.txt", "r");
if (fp == NULL) {
printf("Couldn't open file\n");
exit(-1);
}
while(fgets(line, sizeof(line), fp) != NULL) comb_count++;
fclose(fp);
}
void read_authentication(char ***user_names, char ***passwords){
FILE *fp;
char line[500];
int name_len = 10;
int pass_len = 10;
fp = fopen("Authentication.txt", "r");
if (fp == NULL) {
printf("Couldn't open file\n");
exit(-1);
}
fgets(line, sizeof(line), fp); // Skip first line
for(int i=0; i < user_count; i++){
fgets(line, sizeof(line), fp);
char *split = strtok(line, " \t");
strcpy(*(*(user_names)+i), split);
split = strtok(NULL, " \t"); // Second split in 8 char in length. DONT KNOW WHY. SHOULD BE 6.
strcpy(*(*(passwords)+i), split);
}
fclose(fp);
// # pragma omp parallel
for(int i=0; i < user_count; i++){
*(*((*passwords)+i) + 6) = '\0'; // Terminate password after 6th character
}
}
void read_hangman(char ***combinations){
FILE *fp;
char line[500];
fp = fopen("hangman_text.txt", "r");
if (fp == NULL) {
printf("Couldn't open file\n");
exit(-1);
}
for(int i=0; i < comb_count; i++){
fgets(line, sizeof(line), fp);
if (strlen(line) > 2){
for(int j=0; j < strlen(line); j++){
if(line[j] == ','){
*((*((*combinations)+i))+j) = ' ';
}
else if(line[j] == '\n'){
// Do Nothing
}
else {
*((*((*combinations)+i))+j) = line[j];
}
}
}
}
fclose(fp);
}