diff options
| author | Thomas Schmucker <ts@its1.de> | 2020-06-22 17:20:00 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2020-06-22 17:20:00 +0200 |
| commit | 4bf39b20162e7d12a53a1de607a6f83b159928f5 (patch) | |
| tree | 161740563c56beef1047fc9649b8bfb071b92df0 /csv.c | |
| parent | 5720780289ecd40816adbc0299fe80f0b5d7d37d (diff) | |
| download | libcsv-4bf39b20162e7d12a53a1de607a6f83b159928f5.tar.gz libcsv-4bf39b20162e7d12a53a1de607a6f83b159928f5.tar.bz2 libcsv-4bf39b20162e7d12a53a1de607a6f83b159928f5.zip | |
fix: csv_write
Diffstat (limited to 'csv.c')
| -rw-r--r-- | csv.c | 20 |
1 files changed, 12 insertions, 8 deletions
| @@ -458,22 +458,26 @@ csv_write_field(FILE *out, const char *field, const csv_options_t * const csv_op | |||
| 458 | } | 458 | } |
| 459 | 459 | ||
| 460 | void | 460 | void |
| 461 | csv_write(FILE *out, int n, const char *fields[], const csv_options_t * const csv_options) | 461 | csv_write(FILE *out, int n, const char *fields[], const csv_options_t * csv_options) |
| 462 | { | 462 | { |
| 463 | assert(csv_options != NULL); | ||
| 464 | assert(fields != NULL); | ||
| 465 | assert(out != NULL); | 463 | assert(out != NULL); |
| 464 | assert(fields != NULL); | ||
| 465 | |||
| 466 | if ( csv_options == NULL ) { | ||
| 467 | csv_options = &csv_default_options; | ||
| 468 | } | ||
| 466 | 469 | ||
| 467 | const char SEP = csv_options->quote_symbol; | 470 | const char SEP = csv_options->sep_symbol; |
| 468 | 471 | ||
| 469 | /* process first field */ | 472 | /* process first field */ |
| 470 | if ( 0 != n && fields[0] != NULL ) { | 473 | if ( 0 != n && *fields != NULL ) { |
| 471 | csv_write_field(out, fields[0], csv_options); | 474 | --n; |
| 475 | csv_write_field(out, *fields++, csv_options); | ||
| 472 | 476 | ||
| 473 | /* process next fields */ | 477 | /* process next fields */ |
| 474 | for ( int i = 1; i != n && fields[i] != NULL; ++i ) { | 478 | for ( ; n && *fields != NULL; --n, ++fields ) { |
| 475 | putc(SEP, out); | 479 | putc(SEP, out); |
| 476 | csv_write_field(out, fields[i], csv_options); | 480 | csv_write_field(out, *fields, csv_options); |
| 477 | } | 481 | } |
| 478 | } | 482 | } |
| 479 | fprintf(out, "\r\n"); | 483 | fprintf(out, "\r\n"); |
