I have a data file that, if I was using C++, I would use the getline function to read its data into the proper variables. However, the getline functions that C++ allows appear to not be available to me in C. I want to be able to specify a stream, specify a delimiter, and have the function be portable. I've found this getline function from GNU:
but it says it is non-standard (so I assume that means I cannot assume it will work on all compilers), plus it does not allow me to specify a delimiter. Basically I am dealing with a comma-separated-value file:
I want to read from the file and parse the data into an array of strings, and throw away the comma delimiters and the white space:
I see no way to specify a comma as a delimiter in the getline function above, nor do I see a pre-written function in C that will allow me to do this.
The strtok function looks somewhat promising for this job, but the data is in a file, not a char*, so I don't see how to use it here. Any ideas on how to do this in C? Do I need to write my own getline function that takes a delimiter and a FILE* as two of the parameters?