Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
350 changes: 323 additions & 27 deletions src/csv.c → csv.h

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions examples/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#define CSV_IMPLEMENTATION
#include "../csv.h"

/*
* Row and col to experiment with
*/
#define ROW_TO_MODIFY 10
#define COL_TO_MODIFY 9

int main () {

/*
* Create buffer and load csv data into it
*/
CSV_BUFFER *my_buffer = csv_create_buffer();
printf("created buffer\n");
csv_load(my_buffer, "examples/testlist.csv");

/*
* Print buffer (CSV data loaded)
*/
printf("PRINT DATA:");
print_buffer(my_buffer);

/*
* Play with setting fields
*/
printf("loaded from file\n");
csv_set_field(my_buffer, ROW_TO_MODIFY, COL_TO_MODIFY, "test");
printf("set first field to \"test\"\n");
/*
* Save the changed data to ./examples/
*/
csv_save("examples/testsave.csv", my_buffer);
printf("saved buffer\n");
char *my_string = malloc(ROW_TO_MODIFY + 1);
/*
* Play with getting fields
*/
csv_get_field(my_string, ROW_TO_MODIFY, my_buffer, ROW_TO_MODIFY, COL_TO_MODIFY);
printf("Got string = \"%s\"\n", my_string);
/*
* Always remember to free up the space allocated
*/
csv_destroy_buffer(my_buffer);
printf("destroyed buffer\n");
free(my_string);
printf("Free'd string\n");
return 0;
}
23 changes: 0 additions & 23 deletions examples/example1.c

This file was deleted.

12 changes: 0 additions & 12 deletions examples/print_buffer.c

This file was deleted.

1 change: 0 additions & 1 deletion examples/testlist.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ Strawberry,0.98,1.1,red,3,"I ate all of mine. Betty only ate two."
Banana,0.66,5,green,1,"Maybe not ripe? ""It made my tongue pucker up."" - Betty"
Blueberry,0.04,0.25,blue,18,"Really good. Betty says, ""I couldn't get enough!"""
Grape,0.03,0.125,purple,6,"Not bad. Betty said, ""they were so small"", but I thought they were kind of big."
single
Apple,0.4,2.5,green,2,Good.
11 changes: 11 additions & 0 deletions examples/testsave.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Type,Weight,Height,Color,Number,How was it?
Apple,0.5,3,red,1,Great! We loved it!
Banana,0.65,6,yellow,1,"Not bad, not as crunchy."
Strawberry,0.98,1.1,red,3,I ate all of mine. Betty only ate two.
Banana,0.66,5,green,1,"Maybe not ripe? ""It made my tongue pucker up."" - Betty"
Blueberry,0.04,0.25,blue,18,"Really good. Betty says, ""I couldn't get enough!"""
Grape,0.03,0.125,purple,6,"Not bad. Betty said, ""they were so small"", but I thought they were kind of big."
Apple,0.4,2.5,green,2,Good.


,,,,,,,,,test
275 changes: 0 additions & 275 deletions src/csv.h

This file was deleted.

11 changes: 11 additions & 0 deletions testsave.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@










,,,,,,,,,test