init
This commit is contained in:
35
src/libcsvparser.c
Normal file
35
src/libcsvparser.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user