This commit is contained in:
2023-10-19 08:33:26 -04:00
commit 9f9476c233
6 changed files with 92 additions and 0 deletions

35
src/libcsvparser.c Normal file
View File

@@ -0,0 +1,35 @@
/*
libcsvparser.c - simple CSV parser
*/
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define MAXCHAR 1000
int
parse_tokens(char *file)
{
FILE *fp;
char row[MAXCHAR];
char *token;
fp = fopen(file, "r");
if (fp == NULL) {
printf("csv file %s not found\n", file);
return 1;
}
while (feof(fp) != true) {
fgets(row, MAXCHAR, fp);
token = strtok(row, ",");
while (token != NULL) {
printf("%s\n", token);
token = strtok(NULL, ",");
}
}
return 0;
}