init
This commit is contained in:
commit
9f9476c233
9
Makefile
Normal file
9
Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
include config.mk
|
||||
|
||||
all:
|
||||
$(CC) -c src/libcsvparser.c -o src/libcsvparser.o
|
||||
ar -rc src/libcsvparser.a src/libcsvparser.o
|
||||
|
||||
install:
|
||||
install src/libcsvparser.a $(PREFIX)/lib
|
||||
install include/libcsvparser.h $(PREFIX)/include
|
19
README
Normal file
19
README
Normal file
@ -0,0 +1,19 @@
|
||||
+ libcsvparser
|
||||
|
||||
A very simple CSV parsing library
|
||||
|
||||
+ Usage
|
||||
|
||||
#include <csvparser.h>
|
||||
|
||||
int main() {
|
||||
parse_tokens(FILE);
|
||||
}
|
||||
|
||||
(user)$ gcc prog.c -lcsvparser -o prog
|
||||
|
||||
See 'man 3 libcsvparser' for more information.
|
||||
|
||||
+ Installation
|
||||
|
||||
Customize config.mk, then run 'make', followed by 'make install' as root.
|
7
include/csvparser.h
Normal file
7
include/csvparser.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef CSVPARSER_H_
|
||||
#define CSVPARSER_H_
|
||||
|
||||
/* Functions */
|
||||
int parse_tokens(char *file);
|
||||
|
||||
#endif
|
16
man/libcsvparser.3
Normal file
16
man/libcsvparser.3
Normal file
@ -0,0 +1,16 @@
|
||||
.\" Manpage for libcsvparser.
|
||||
.TH man 3 "19 October 2023" "1.0" "Everest Linux Libraries Manual"
|
||||
.SH NAME
|
||||
libcsvparser \- csv parsing library
|
||||
.SH SYNOPSIS
|
||||
#include <csvparser.h>
|
||||
|
||||
parse_tokens(FILE);
|
||||
|
||||
(user)$ gcc -lcsvparser prog.c -o prog
|
||||
.SH DESCRIPTION
|
||||
libcsvparser is a library that can read a .csv file and print out its tokens individually. It is provided as a static library only.
|
||||
.SH BUGS
|
||||
Report all bugs on the issues page at https://git.everestlinux.org/EverestLinux/libcsvparser
|
||||
.SH AUTHOR
|
||||
Liam Waldron (liamwaldron@everestlinux.org)
|
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user