45 lines
950 B
C
45 lines
950 B
C
|
#include "../include/easycsv/easycsv.h"
|
||
|
|
||
|
#define CSV_FP "01.csv"
|
||
|
#define CSV_MODE "r"
|
||
|
|
||
|
int main(int argc, char **argv)
|
||
|
{
|
||
|
if (argc < 2) {
|
||
|
fprintf(stderr, "No arguments!\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
struct easycsv *csv = easycsv_init(CSV_FP, CSV_MODE);
|
||
|
|
||
|
if (access(CSV_FP, F_OK) < 0) {
|
||
|
fprintf(stderr, "%s cannot be found!\n", CSV_FP);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
if (csv == NULL) {
|
||
|
fprintf(stderr, "Failed to initialise %s on mode %s\n", CSV_FP, CSV_MODE);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
printf("COLUMNS: %i\nROWS: %i\n", easycsv_rows(csv), easycsv_columns(csv));
|
||
|
|
||
|
// char *str = malloc(EASYCSV_BUFFER_SIZE);
|
||
|
|
||
|
printf("Searching column values of %s...\n", argv[1]);
|
||
|
|
||
|
for (int i = 2;;i++) {
|
||
|
char *null = (char*) easycsv_readcolumnvalue(csv, argv[1], i);
|
||
|
if (null == NULL) {
|
||
|
free(null);
|
||
|
puts("End of file!\n");
|
||
|
break;
|
||
|
}
|
||
|
printf("ROW %i: %s\n", i, null);
|
||
|
}
|
||
|
|
||
|
easycsv_free(csv);
|
||
|
csv = NULL;
|
||
|
return 0;
|
||
|
}
|