I'm trying to produce code to read input from a comma separated text file line by line. I'm only interested in 3 of the fields, so I'm skipping over the rest. Problem is that 2 of the fields are string contained in quotation marks, and one of them is actually optional.
For example, two successive lines might look like:
0,,10004,10004,"Albany Hwy After Galliers Av","",-32.13649428,116.0176090070,3
0,,10005,10005,"Albany Hwy Armadale Kelmscott Hospital","Armadale Kelmscott Hospital",-32.13481555555560,116.017707222222,3
Since I'm not interested in the strings (I'm only interested in a few of the numbers), I'm just skipping over them using the * operator in scanf. For the first string, it's easy, since that's a mandatory field, so I can just skip the first double quote match to a regex of everything up to the second double quote, like so:
\"%*[^\"]
What I'm having trouble with is the second field, right after the first. The problem is that this field is optional; thus it may have text, it may not. Whenever it doesn't, the regex I listed above doesn't work properly, and the whole scanf operation fails for that line. Despite my best efforts, I cannot produce a regex that successfully matches everything up to the second double quotation mark, as well as matching empty strings. Does anyone know how I could modify my regex to perform such a function?
p.s. here is an example of what my scanf operation looks like:
res = sscanf(buf, "%*d,,%ld,%*ld,\"%*[^\"]\",\"%*[]\",%lf,%lf,%*d", &cursid, &curslat, &curslong);