Reputation: 101
I have a file with the following content
"AAA";"BBB"
I try to extract the 2 columns this way :
char v1[50];
char v2[50];
int ret = fscanf(fp, "\"%s\";\"%s\"", v1, v2);
But it returns 1 and everything in 'v1' !
Is it normal ?
Upvotes: 4
Views: 50
Reputation: 409442
It's because the "%s"
format reads space delimited strings. It will read the input until it hits a white-space or the end of the input.
You could possibly use the "%["
format here, maybe something like
fscanf(fp, "\"%[^\"]\";\"%[^\"]\"", v1, v2);
See e.g. this scanf
(and family) reference for more information.
Upvotes: 5