-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfileConfig.c
More file actions
71 lines (60 loc) · 1.99 KB
/
fileConfig.c
File metadata and controls
71 lines (60 loc) · 1.99 KB
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
//
// Created by kbod on 16/02/2022.
//
void fileConfig(char *window_size_x, char *window_size_y,char *hostDB,char *nameDB){
char *filename = "../config.txt"; //path from current dir
FILE *fp = fopen(filename, "r");
if (fp == NULL)
{
printf("Erreur: Impossible d'ouvrir le fichier %s", filename);
exit(1);
}
// reading line by line, max 150 bytes/lines
const int MAX_LENGTH = 150, MAX_ROW = 20;
char line[MAX_LENGTH];
int i,j=0,k=0;
char tmpResult[MAX_LENGTH][MAX_LENGTH];
while (fgets(line, MAX_LENGTH, fp)) {
//recupere les lignes du fichier
if (strlen(line)>2){
for (i = 0; i < strlen(line); i++) {
if (line[i] != 58 && line[i] != EOF && line[i] != 59){
tmpResult[j][k] = line[i];
k++;
} else{
k++;
tmpResult[j][k] = '\0';
j++;
k = 0;
}
}
k=0;
j++;
}
}
// close the file
if (fclose(fp)!=0) {
printf("fichier non fermé");
}
//set variables
for (i = 0; i < MAX_ROW; ++i) {
if (strcmp(tmpResult[i], "window_size_x")==0){
strcpy(window_size_x,tmpResult[i+1]);
//printf("\nla variable window_size_x = %s", window_size_x);
//printf("\nla size = %d", strlen(tmpResult[i+1]));
i++;
} else if (strcmp(tmpResult[i], "window_size_y")==0){
strcpy(window_size_y,tmpResult[i+1]);
//printf("la variable window_size_y = %s", window_size_y);
i++;
} else if (strcmp(tmpResult[i], "host")==0){
strcpy(hostDB,tmpResult[i+1]);
//printf("la variable host = %s", hostDB);
i++;
} else if (strcmp(tmpResult[i], "database")==0){
strcpy(nameDB,tmpResult[i+1]);
//printf("la variable nameDB = %s", nameDB);
i++;
}
}
}