Scanf and format?

I have a file with the following contents

"AAA";"BBB"

I am trying to extract 2 columns as follows:

char v1[50];
char v2[50];
int ret = fscanf(fp, "\"%s\";\"%s\"", v1, v2);

But it returns 1 and everything in 'v1'!

This is normal?

+4
source share
1 answer

This is because the format "%s"reads space-delimited lines. It will read the input until it reaches a space or the end of the input.

Maybe you can use the format "%[", maybe something like

fscanf(fp, "\"%[^\"]\";\"%[^\"]\"", v1, v2);

See this link scanf(and family) for more information.

+5
source

Source: https://habr.com/ru/post/1620121/


All Articles