|
|
|
@ -88,46 +88,21 @@ easycsv_columns(const easycsv *csv)
|
|
|
|
|
return col; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* char* */ |
|
|
|
|
/* _easycsv_getrow(const _easycsv *csv, */ |
|
|
|
|
/* const unsigned int row) */ |
|
|
|
|
/* { */ |
|
|
|
|
/* /\* ARGS CHECK *\/ */ |
|
|
|
|
/* if (csv == NULL) { */ |
|
|
|
|
/* _easycsv_printerror(csv, EASYCSV_NULLCSV); */ |
|
|
|
|
/* return NULL; */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* if (row > csv->rows) { */ |
|
|
|
|
/* _easycsv_printerror(csv, EASYCSV_OVERMAXROW); */ |
|
|
|
|
/* return NULL; */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* if (row == 0) { */ |
|
|
|
|
/* _easycsv_printerror(csv, EASYCSV_ZEROROW); */ |
|
|
|
|
/* return NULL; */ |
|
|
|
|
/* } */ |
|
|
|
|
/* /\* END ARGS CHECK *\/ */ |
|
|
|
|
|
|
|
|
|
/* /\* Allocate memory *\/ */ |
|
|
|
|
/* char *str = malloc(BUFSIZ); */ |
|
|
|
|
|
|
|
|
|
/* /\* Set file pointer to start *\/ */ |
|
|
|
|
/* rewind(csv->file); */ |
|
|
|
|
char* |
|
|
|
|
easycsv_get_row(const easycsv *csv, |
|
|
|
|
unsigned int row) |
|
|
|
|
{ |
|
|
|
|
char *str = malloc(BUFSIZ); |
|
|
|
|
easycsv_rewind(csv); |
|
|
|
|
|
|
|
|
|
/* for (int i = 1; i < row; i++) */ |
|
|
|
|
/* { */ |
|
|
|
|
/* /\* skip until row is reached *\/ */ |
|
|
|
|
/* fscanf(csv->file, "%*[^\n]\n", NULL); */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* /\* Grab the row and store it in str *\/ */ |
|
|
|
|
/* fscanf(csv->file, "%s\n", str); */ |
|
|
|
|
for (int i = 1; i < row; i++) { |
|
|
|
|
fscanf(csv->file, "%*[^\n]\n", NULL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* // printf("row: %s\n", str); */ |
|
|
|
|
fscanf(csv->file, "%s\n", str); |
|
|
|
|
|
|
|
|
|
/* return str; */ |
|
|
|
|
/* } */ |
|
|
|
|
return str; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
easycsv_rewind(const easycsv *csv) |
|
|
|
@ -247,24 +222,19 @@ int _easycsv_checkifvalue(struct easycsv *csv, const int col, const int row)
|
|
|
|
|
/* return val; */ |
|
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
/* char* */ |
|
|
|
|
/* _easycsv_setcharptovalue(const _easycsv *_priv, */ |
|
|
|
|
/* const char *rowstr, */ |
|
|
|
|
/* const unsigned int col) */ |
|
|
|
|
/* { */ |
|
|
|
|
/* char *pch = rowstr; */ |
|
|
|
|
|
|
|
|
|
/* for (unsigned int i = 1; i < col; i++) { */ |
|
|
|
|
/* pch = strchr(rowstr, ','); */ |
|
|
|
|
/* if (pch == NULL) { */ |
|
|
|
|
/* _easycsv_printerror(_priv, EASYCSV_NULLPTR); */ |
|
|
|
|
/* return NULL; */ |
|
|
|
|
/* } */ |
|
|
|
|
/* pch++; */ |
|
|
|
|
/* } */ |
|
|
|
|
char* |
|
|
|
|
easycsv_set_charp_to_value(const char *rowstr, |
|
|
|
|
unsigned int col) |
|
|
|
|
{ |
|
|
|
|
/* Get first occurance of comma in str, the first value is ommited but not the comma */ |
|
|
|
|
char *pch = (char*) rowstr; |
|
|
|
|
/* Repeat until desired col is found */ |
|
|
|
|
for (unsigned int i = 1; i < col; i++) { |
|
|
|
|
pch = strpbrk(pch + 1, ","); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* return pch; */ |
|
|
|
|
/* } */ |
|
|
|
|
return pch; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* int */ |
|
|
|
|
/* _easycsv_checkcsvandstring_one(const _easycsv *csv, */ |
|
|
|
|