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
|
#include <stdio.h>
#include <stdlib.h>
#include "ed/inc/io.h"
#include "ed/inc/tok.h"
#define F "inscriptionsweb.csv"
static int cb_list(char const *s, size_t rank, void *puser)
{
char **pp_headers = puser;
if (pp_headers != NULL)
{
if (*s != 0)
{
printf ("[%2d] %-10s= %s\n", rank, pp_headers[rank], s);
}
}
return 0;
}
int main ()
{
FILE *fp = fopen(F, "r");
if (fp != NULL)
{
int err;
char *first_line = fget_line(fp, &err);
if (first_line != NULL)
{
sTOK * ptok_first = TOK_create(first_line, ";", NULL);
if (ptok_first != NULL)
{
sTOK_INFO headers;
/* recuperer la liste des headers */
TOK_get (ptok_first, &headers);
if (headers.argv != NULL)
{
char *line;
while ((line = fget_line(fp, &err)) != NULL)
{
sTOK * ptok = TOK_create(line, ";", NULL);
if (ptok != NULL)
{
TOK_list(ptok, cb_list, headers.argv);
printf ("\n");
free (line), line = NULL;
TOK_delete(ptok), ptok = NULL;
}
}
}
TOK_delete(ptok_first), ptok_first = NULL;
}
free (first_line), first_line = NULL;
}
fclose (fp), fp = NULL;
}
else
{
perror(F);
}
return 0;
} |
Partager