diff options
| -rw-r--r-- | csv.c | 16 |
1 files changed, 11 insertions, 5 deletions
| @@ -479,18 +479,23 @@ csv_write(FILE *out, const csv_t * const csv) | |||
| 479 | 479 | ||
| 480 | const char SEP = csv->csv_options->field_separator; | 480 | const char SEP = csv->csv_options->field_separator; |
| 481 | 481 | ||
| 482 | |||
| 482 | if ( 0 < csv->csv_field.pos ) { | 483 | if ( 0 < csv->csv_field.pos ) { |
| 483 | csv_write_field(out, csv_field(csv, 0), csv->csv_options); | 484 | const char *str = csv->csv_string.str; |
| 485 | const int *field = csv->csv_field.fields; | ||
| 486 | |||
| 487 | csv_write_field(out, &str[*field++], csv->csv_options); | ||
| 484 | 488 | ||
| 485 | for ( int i = 1; i < csv->csv_field.pos; ++i ) { | 489 | for ( int i = 1; i < csv->csv_field.pos; ++i ) { |
| 486 | putc(SEP, out); | 490 | putc(SEP, out); |
| 487 | csv_write_field(out, csv_field(csv, i), csv->csv_options); | 491 | csv_write_field(out, &str[*field++], csv->csv_options); |
| 488 | } | 492 | } |
| 489 | } | 493 | } |
| 490 | fprintf(out, "\r\n"); | 494 | putc('\r', out); |
| 495 | putc('\n', out); | ||
| 491 | 496 | ||
| 492 | if ( ferror(out) ) { | 497 | if ( ferror(out) ) { |
| 493 | csv_fatal_error(CSV_ERR_IO_WRITE, csv_options); | 498 | csv_fatal_error(CSV_ERR_IO_WRITE, csv->csv_options); |
| 494 | } | 499 | } |
| 495 | } | 500 | } |
| 496 | 501 | ||
| @@ -517,7 +522,8 @@ csv_write_ex(FILE *out, int n, const char *fields[], const csv_options_t * csv_o | |||
| 517 | csv_write_field(out, *fields, csv_options); | 522 | csv_write_field(out, *fields, csv_options); |
| 518 | } | 523 | } |
| 519 | } | 524 | } |
| 520 | fprintf(out, "\r\n"); | 525 | putc('\r', out); |
| 526 | putc('\n', out); | ||
| 521 | 527 | ||
| 522 | if ( ferror(out) ) { | 528 | if ( ferror(out) ) { |
| 523 | csv_fatal_error(CSV_ERR_IO_WRITE, csv_options); | 529 | csv_fatal_error(CSV_ERR_IO_WRITE, csv_options); |
