commit 31c1745c34d6adeb93fcd40d55aa43cedc80b6ec
parent c13189446dd8f040b669db70ea5fd93a62959fc5
Author: aabacchus <ben@bvnf.space>
Date: Sat, 2 Oct 2021 20:34:33 +0100
add header file
Diffstat:
M | csv.c | | | 14 | +++----------- |
A | csv.h | | | 19 | +++++++++++++++++++ |
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/csv.c b/csv.c
@@ -3,18 +3,10 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include "csv.h"
#define MAX_LINE 2048
-struct csv {
- int cols, rows;
- char **headers; /* array of strings */
- float **data; /* array of arrays of floats */
-};
-
-int
-csv_read_file(FILE *, struct csv *, char hdr);
-
struct csv *
csv_create(void) {
struct csv *c;
@@ -52,7 +44,7 @@ csv_destroy(struct csv *c) {
* into *header, and returns the number of columns.
* This function mallocs the returned value of fields in *header[0..n-1]
*/
-int
+static int
read_header(FILE *f, char **header) {
char **headerp = header;
int c;
@@ -81,7 +73,7 @@ read_header(FILE *f, char **header) {
* This function mallocs the number of rows in *header[0..n-1]
* -1 is returned on error.
*/
-int
+static int
read_data(FILE *f, float ***datap, int ncols) {
float **data = *datap;
int nrows = 0;
diff --git a/csv.h b/csv.h
@@ -0,0 +1,19 @@
+#ifndef _CSV_H
+#define _CSV_H
+
+struct csv {
+ int cols, rows;
+ char **headers; /* array of strings */
+ float **data; /* array of arrays of floats */
+};
+
+struct csv *
+csv_create(void);
+
+void
+csv_destroy(struct csv *c);
+
+int
+csv_read_file(FILE *stream, struct csv *c, char hdr);
+
+#endif