Hello!
I am rather new to c, and I am having a parsing problem.
What I am trying to accomplish:
I have a file filled with assignment statements such as:
var1=5
var2=80
...etc.
I want to parse through the file and then do a check to see if the variables exist in my main program. If they do, then I will override the default value with the one from the config file, if not, then I will just ignore them.
I have an idea how to open the file, and I kind of know how to parse the lines at the =, but from there I am lost.
Here is my code so far:
#include <stdio.h>
#include <string.h>
int main(void){
static const char filename[] = ".configfile";
FILE *file = fopen(filename, "r");
if (file){
char line[BUFSIZ];
int k = 0;
while ( fgets(line, sizeof line, file) ){
int i;
char *token = line;
for(i=0; *token; ++i){
size_t len = strcspn(token, "=");
#Oh man, now what?
#No idea what to do here!
# :(
token += len + 1;
}
}
fclose(file);
else{
#set defaults
}
}
return 0;
}
Thanks in advance!