how to read optional characters %*[] with fscanf?
I'm trying to read a file into 2 variables, ignoring optional quote (") characters for the first value, while picking up remaining the 2nd variable (which can contain a space). It doesn't seem to be quite right. I can't use a perl script and have to use C. How would I do this? Can anyone help, please? When I use the %*[\"] option to gobble up any quotes ("), it won't read the line if a quote isn't there. I think that's the main problem.
Input File:
Hello bye
"Hi" good bye
Desired Output:
Var 1: [Hello]
Var 2: [bye]
Var 1: [Hi]
Var 2: [good bye]
This is what I have so far:
while (fscanf(fin, "%*[\"]%[^,\" \t]%*[\", \t]%[^,\t\n]%*[,\n]", var1, var2) == 2)
{
printf("Var 1: [%s]\n", var1);
printf("Var 2: [%s]\n", var2);
}
Last edited by phyx; 01-18-2007 at 12:56 PM.
|