I have a struct OPTS
which contains a few char
s and char[]
s. I also have a file opts.cnf which can be edited in a text editor like vim. I want to read the opts.cnf and assign the values from that file to my struct.
opts.h
typedef struct OPTS {
char opt1;
char opt2[6];
char opt3;
}
opts.cnf
OPT1=Y
OPT2=1234
OPT3=D
opts.c
while (fgets (work, sizeof (work), file) ) {
if (!strncmp (work, "OPTS1=", 6) ) {
optptr->opt1 = topper(work[6]);
}
if (!strncmp (work, "OPTS2=", 6) ) {
sprintf(optptr->opt2, "%-4.4s", &work[6]);
}
if (!strncmp (work, "OPTS3=", 6) ) {
optptr->opt3 = topper(work[6]);
}
}
Is there a more efficient way to go about this? I need to be able to edit opts.cnf
inside of a text editor but different formats are welcome if they make it more efficient.