From 39e273aca7859af1b573a9055e34bdf57e38ffe4 Mon Sep 17 00:00:00 2001 From: Fleroy Date: Wed, 16 May 2018 08:31:32 +0200 Subject: [PATCH] sauvegarde fichier initial --- src/csv_reader.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/csv_reader.c b/src/csv_reader.c index f65f86a..a753d56 100644 --- a/src/csv_reader.c +++ b/src/csv_reader.c @@ -4,7 +4,7 @@ #include // Conditionals -const bool IS_DEBUG = false; +const bool IS_DEBUG = true; // Constants const unsigned int BUFFER_SIZE = 2048; @@ -15,6 +15,23 @@ const char CSV_DELIMITERS[] = ","; char** CSV_HEADER_FIELDS; unsigned int CSV_NB_FIELDS; +char *strtok_new(char * string, char const * delimiter) +{ + static char *source = NULL; + char *p, *ret = 0; + if(string != NULL) source = string; + if(source == NULL) return NULL; + + if( (p = strpbrk(source, delimiter)) != NULL) + { + *p = 0; + ret = source; + source = ++p; + } + return ret; +} + + void display_header() { for(unsigned int i = 0; i < CSV_NB_FIELDS; i++) @@ -81,7 +98,7 @@ void read_csv_file(const char * filename) unsigned int i = 0; // strtok init. - token = strtok(buffer, CSV_DELIMITERS); + token = strtok_new(buffer, CSV_DELIMITERS); while (NULL != token) { @@ -91,7 +108,7 @@ void read_csv_file(const char * filename) // you can strcpy the `token` string in your data structures // ... - token = strtok(NULL, CSV_DELIMITERS); + token = strtok_new(NULL, CSV_DELIMITERS); } } -- libgit2 0.21.2