-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvReader.h
More file actions
50 lines (39 loc) · 1.01 KB
/
csvReader.h
File metadata and controls
50 lines (39 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef CSVREADER_H
#define CSVREADER_H
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#define MAX_CSV_HEADER 50
typedef struct CsvFileMems{
FILE *file;
int colSize;
double *dataRow;
char *headers[MAX_CSV_HEADER];
double (*GetField)(struct CsvFileMems *csv, const char *field);
} CSVFILE;
/**
* @brief open csv file, return true if file exists.
* @param csvFile: CSVFILE struct.
* @param filename: filename
* @retval bool
*/
bool csvOpen(CSVFILE *csvFile, const char *filename);
/**
* @brief read csv line by line.
* if return true, you can get the whole array or get the data by header.
*
* @sample
* CSVFILE file;
* if(csvOpen(&file, filename)){
* while(csvReadLine(&file)){
* // do something...
* }
* }
*/
bool csvReadLine(CSVFILE *csvFile);
typedef void(*CsvRowUpdate)(CSVFILE *csvFile);
/**
* @brief use a callback function to handle the data update.
*/
void csvReadCallback(const char *filename, CsvRowUpdate callback);
#endif // CSVREADER_H