-
Notifications
You must be signed in to change notification settings - Fork 0
/
switchServer.c
71 lines (67 loc) · 1.76 KB
/
switchServer.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
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
typedef struct configuracion{
char ip[50];
char user[50];
char pwd[50];
char dbName[50];
}config_t;
config_t* configReader(){
FILE* archivo= NULL;
char* confPath= "server.conf";
char lectura[50];
config_t* conf = malloc(sizeof(config_t));
archivo = fopen(confPath,"r");
if (archivo == NULL){
printf("\nError: El archivo de configuracion no se pudo cargar\n Verifique si este se encuentra en la carpeta del servidor\n");
}else{
char c;
int i=0;
while (feof(archivo) == 0){
fscanf(archivo,"%s\n",&lectura);
c = lectura[0];
if (c == '#'){
continue;
}else{
i=i+1;
switch (i){
case 1:
strncpy(&conf->ip,&lectura,50);
break;
case 2:
strncpy(&conf->user,&lectura,50);
break;
case 3:
strncpy(&conf->pwd,&lectura,50);
break;
case 4:
strncpy(&conf->dbName,&lectura,50);
break;
default:
break;
}
}
}
fclose(archivo);
return conf;
}
}
int main(){
char *resp;
printf("Wellcome to MDBC \n");
printf(">Multi Database Connector\n\n\n");
config_t* conf = NULL;
conf = configReader();
printf("\nValores establecidos -----\n");
printf("IP: %s\n",&conf->ip);
printf("User: %s\n",&conf->user);
printf("PWD: %s\n",&conf->pwd);
printf("DBName: %s\n",&conf->dbName);
printf("--------------------------\n");
//funcionMysql(&conf->ip,&conf->user,&conf->pwd,&conf->dbName,"select * from city");
return 0;
}