UCFD_SPARSE  v1.0
Documentation
Loading...
Searching...
No Matches
readinput.c
Go to the documentation of this file.
1
21#include <regex.h>
22#include <stdio.h>
23#include <string.h>
24#include <stdlib.h>
25#include "readinput.h"
26
27void input_params(FILE *fp, int *vars)
28{
29 /* File read variables */
30 char *line = NULL;
31 size_t len = 0;
32 ssize_t read;
33
34 /* regex variables */
35 regex_t pattern;
36 regmatch_t groupArray;
37 char *scopy = NULL;
38 int nwidth;
39 int index = 0;
40
41 regcomp(&pattern, "[[:digit:]]+", REG_EXTENDED);
42
43 while((read = getline(&line, &len, fp)) != -1) {
44
45 if (regexec(&pattern, line, 1, &groupArray, 0) == 0) {
46 scopy = line;
47 while (regexec(&pattern, scopy, 1, &groupArray, 0) != REG_NOMATCH) {
48 regexec(&pattern, scopy, 1, &groupArray, 0);
49 scopy += groupArray.rm_so;
50 nwidth = groupArray.rm_eo - groupArray.rm_so;
51 char strnum[nwidth + 1];
52 strncpy(strnum, scopy, nwidth);
53 vars[index] = atoi(strnum);
54 scopy += groupArray.rm_eo;
55 index++;
56 }
57 }
58 }
59 regfree(&pattern);
60}
61
62
63
64
65
66
67
void input_params(FILE *fp, int *vars)
Definition: readinput.c:27