Skip to content

surajkareppagol/libcsv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📊 libcsv

Yet another library for CSV files.

⚙️ Build Executable

Build and run the example.

make
libcsv [options...]
libcsv -i users.csv -a "user,2002,admin,new" -p -e

📦️ Build Static Library

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

➡️ Available Options

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

⚙️ API

1. CSV_IMPORT

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);

2. CSV_EXPORT

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);

3. CSV_FIELD

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);

4. CSV_COLUMN

Similar to csv_field(), but accepts column number (starts from 0).

void *csv_column(unsigned int column, CSV_LIST *csv_list, CSV_METADATA *metadata);

5. CSV_ADD_ROW

Add new row of data to CSV list.

void csv_add_row(char *data, CSV_LIST *csv_list, CSV_METADATA *metadata);

6. CSV_REMOVE_ROW

Remove a row of data from CSV list.

void csv_remove_row(unsigned int row, CSV_LIST *csv_list, CSV_METADATA *metadata);

7. CSV_SHOW

Print raw CSV data to the stdout.

void csv_show(CSV_LIST *csv_list, CSV_METADATA *metadata);

8. CSV_CLEAR

Free memory used by CSV structure.

void csv_clear(CSV_LIST *csv_list, CSV_METADATA *metadata);