-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSV_reader.c
More file actions
59 lines (52 loc) · 941 Bytes
/
Copy pathCSV_reader.c
File metadata and controls
59 lines (52 loc) · 941 Bytes
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
51
52
53
54
55
56
57
58
59
//
// CSV_reader.c
// OpenDMX
//
// Created by Patrick Marx on 25.08.17.
// Copyright © 2017 Patrick Marx. All rights reserved.
//
#include "CSV_reader.h"
FILE* fp;
int lines;
int open_csv(char* filename){
fp = fopen(filename, "r");
if(fp == NULL){
return -1;
}
return 0;
}
const char* get_field(char* line, int number)
{
const char* tok;
for (tok = strtok(line, ";"); tok && *tok; tok = strtok(NULL, ";\n")){
if (!--number)
return tok;
}
return NULL;
}
int get_number_lines(){
int ch = 0;
if(fp == 0){
return 0;
}
lines++;
while(!feof(fp)){
ch = fgetc(fp);
if(ch == '\n'){
lines++;
}
}
return lines;
}
void get_array_from_field(int field, int* a, int* b){
rev();
int x = 0;
while((fscanf(fp,"%d;%d\n", &a[x], &b[x])) != EOF) {
fprintf(stdout,"Written: %d;%d\n", a[x], b[x]);
x++;
}
}
void rev(){
fseek(fp, 0L, SEEK_SET);
printf("Reverse\n");
}