diff options
| author | Thomas Schmucker <ts@its1.de> | 2020-06-13 09:12:30 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2020-06-13 09:12:30 +0200 |
| commit | 08284460e7fb28cb9a2d7062934d92f3dc830318 (patch) | |
| tree | 2b5e1e566e639756507b0eaebba3d92a12448d6e /csv-test.c | |
| parent | b4e02e1f0a3fb8c6a01b04d66d05bc246076ce7b (diff) | |
| download | libcsv-08284460e7fb28cb9a2d7062934d92f3dc830318.tar.gz libcsv-08284460e7fb28cb9a2d7062934d92f3dc830318.tar.bz2 libcsv-08284460e7fb28cb9a2d7062934d92f3dc830318.zip | |
funktionen zum Schreiben von CSV-Daten hinzugefügt
Diffstat (limited to 'csv-test.c')
| -rw-r--r-- | csv-test.c | 43 |
1 files changed, 41 insertions, 2 deletions
| @@ -4,8 +4,7 @@ | |||
| 4 | #include <time.h> | 4 | #include <time.h> |
| 5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
| 6 | 6 | ||
| 7 | //#define INLINE static inline | 7 | #define INLINE static inline |
| 8 | #define INLINE /**/ | ||
| 9 | 8 | ||
| 10 | /* === CSV-STRING Interface === */ | 9 | /* === CSV-STRING Interface === */ |
| 11 | 10 | ||
| @@ -298,6 +297,46 @@ csv_read(csv_t *csv, FILE *in) | |||
| 298 | } | 297 | } |
| 299 | } | 298 | } |
| 300 | 299 | ||
| 300 | static void | ||
| 301 | csv_write_field(csv_t *csv, const char *field, FILE *out) | ||
| 302 | { | ||
| 303 | const char QUOTE = csv->csv_options->quote_symbol; | ||
| 304 | |||
| 305 | if ( *field != '\0' ) { | ||
| 306 | putc(QUOTE, out); | ||
| 307 | |||
| 308 | for ( ; *field != '\0'; ++field ) { | ||
| 309 | if ( *field == QUOTE ) { | ||
| 310 | putc(QUOTE, out); | ||
| 311 | putc(QUOTE, out); | ||
| 312 | } | ||
| 313 | else { | ||
| 314 | putc(*field, out); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | |||
| 318 | putc(QUOTE, out); | ||
| 319 | } | ||
| 320 | } | ||
| 321 | |||
| 322 | void | ||
| 323 | csv_write(csv_t *csv, int n, const char *fields[], FILE *out) | ||
| 324 | { | ||
| 325 | const char SEP = csv->csv_options->quote_symbol; | ||
| 326 | |||
| 327 | int i = 0; | ||
| 328 | |||
| 329 | if ( i != n && fields[i] != NULL ) { | ||
| 330 | csv_write_field(csv, fields[i], out); | ||
| 331 | |||
| 332 | for ( i = 1; i != n && fields[i] != NULL; ++i ) { | ||
| 333 | putc(SEP, out); | ||
| 334 | csv_write_field(csv, fields[i], out); | ||
| 335 | } | ||
| 336 | } | ||
| 337 | fprintf(out, "\r\n"); | ||
| 338 | } | ||
| 339 | |||
| 301 | int | 340 | int |
| 302 | main(void) | 341 | main(void) |
| 303 | { | 342 | { |
