I'll describe an approach algorithmically, with some C hints. You can make an attempt to implement this in detail in C:
Read the first line of the configuration file into a string buffer and store the first character into a
delimiter
variable (Note: this assumes of course that the first character of this line is what you want).Read the second line of the configuration file into a string buffer and, using
strtok
and thedelimiter
saved in step 1 as the string delimiter, read each of the column names from that line, copying them into an array of column names (Note: you can have an array ofchar *
with fixed maximum number of elements, and allocate each string memory dynamically as you go, copying the strings from pointers given bystrtok
). In this step, record how many columns you recorded,num_columns
.Open and read the data file line by line. You can use
strtok
here and operate on each string item using whatever method needed. Since your configuration file doesn't indicate data types, you'll need to assume that they're all strings, unless you want to make assumptions based upon certain column names.
That's a basic approach. You can fill in the blanks on error checking and general housekeeping (closing files where appropriate, etc).