-
Notifications
You must be signed in to change notification settings - Fork 0
/
usage_example.c
32 lines (29 loc) · 961 Bytes
/
usage_example.c
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
#include <stdio.h>
#include "csvparser.h"
int main() {
int i = 0;
// file, delimiter, first_line_is_header?
CsvParser *csvparser = CsvParser_new("Book1.csv", ",", 1);
CsvRow *header;
CsvRow *row;
header = CsvParser_getHeader(csvparser);
if (header == NULL) {
printf("%s\n", CsvParser_getErrorMessage(csvparser));
return 1;
}
char **headerFields = CsvParser_getFields(header);
for (i = 0 ; i < CsvParser_getNumFields(header) ; i++) {
printf("TITLE: %s\n", headerFields[i]);
}
CsvParser_destroy_row(header);
while ((row = CsvParser_getRow(csvparser)) ) {
printf("NEW LINE:\n");
char **rowFields = CsvParser_getFields(row);
for (i = 0 ; i < CsvParser_getNumFields(row) ; i++) {
printf("FIELD: %s\n", rowFields[i]);
}
CsvParser_destroy_row(row);
}
CsvParser_destroy(csvparser);
return 0;
}