Yet another library for CSV files.
Build and run the example.
make
libcsv [options...]
libcsv -i users.csv -a "user,2002,admin,new" -p -e
make lib
The static library libcsv.a
is created under lib/
. Build a application
using this static library with the following command.
gcc -I./include csv_application.c -L./lib/ -lcsv
Option | Description | Arguments |
---|---|---|
i | Import CSV | CSV file name required |
a | Append row of data | String of data separated by comma |
r | Remove row of data | Index number (0 - Max items) |
p | Print CSV data | None |
e | Export to CSV file | None |
Pass csv filename and the address of metadata structure. If file found it will extract the data and also fill up the metadata structure. Returns the pointer to the csv list.
CSV_LIST *csv_import(char *csv_file, CSV_METADATA **metadata);
Pass csv list and optional csv filename, also the metadata structure. A csv file will be created and the data from CSV list will be populated.
void csv_export(CSV_LIST *csv_list, char *csv_file, CSV_METADATA *metadata);
Pass field string, CSV list and metadata structure. If field found it will return the pointer to the type block.
void *csv_field(char *field, CSV_LIST *csv_list, CSV_METADATA *metadata);
Similar to csv_field()
, but accepts column number (starts from 0).
void *csv_column(unsigned int column, CSV_LIST *csv_list, CSV_METADATA *metadata);
Add new row of data to CSV list.
void csv_add_row(char *data, CSV_LIST *csv_list, CSV_METADATA *metadata);
Remove a row of data from CSV list.
void csv_remove_row(unsigned int row, CSV_LIST *csv_list, CSV_METADATA *metadata);
Print raw CSV data to the stdout
.
void csv_show(CSV_LIST *csv_list, CSV_METADATA *metadata);
Free memory used by CSV structure.
void csv_clear(CSV_LIST *csv_list, CSV_METADATA *metadata);