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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "term.h"
int _lire_file(const char* path,user_list_t* user)
{
FILE* fd;
char line[BUFSIZ];
if (NULL == (fd = fopen(path,"r")))
{
fprintf(stderr,"Unable to open file\n");
return -1;
}
while(fgets(line, BUFSIZ, fd))
{
printf("%s\n",line);
if (NULL != line) parse_line(line,&user);
}
if (!feof(fd))
{
fprintf(stderr,"Reading process failure!!\n");
return -1;
}
fclose(fd);
printf("\n");
return 0;
}
void parse_line(char* line,user_list_t** user)
{
/*Ligne de type 127.0.0.1:7000@5060*/
user_list_t* tsukai;
char* p;
char* q;
char* tmp;
tsukai = (user_list_t*) malloc(sizeof*tsukai);
tmp = malloc(sizeof*tmp);
/*Adresse IP*/
p = strstr(line,":");
printf("%s\n",p);
if (NULL != p)
{
*p ='\0';
strcpy(tmp,line);
*p =':';
}
tsukai->ip = tmp;
/*Port serveur*/
p++;
q = strstr(p,"@");
printf("q:%s\n",q);
if (NULL != q)
{
*q = '\0';
strcpy(tmp,p);
*q = '@';
}
tsukai->port = tmp;
/*Port client*/
q++;
tsukai->port_clt = q;
}
int main(int argc,char* argv[])
{
const char* path;
path = "/home/jro/doc/exosenc/uri.txt";
user_list_t* user;
user = (user_list_t*) malloc(sizeof*user);
_lire_file(path,user);
return 0;
} |
Partager