Reputation: 21
As an example I have a text file that includes this text: "name?"
I want to save this String only as name?
I tried ("%["]")
, but this doesn't work.
Which function should I use?
Upvotes: 1
Views: 739
Reputation: 409266
The scanf
and fscanf
functions work exactly the same. Your format is however wrong.
Try instead e.g. "\"%[^\"]\""
as your format.
The first and last "
is to mark the start and end of the string. Inside the string one can't use plain double-quote as that will end the string. So these have to be escaped using the backslash.
If we break down the format string into its three main components:
\"
- This matches the literal double-quote%[^\"]
- This matches a string not containing the double-quote (the negation is what the ^
does)\"
again, to match the end quote of your inputUpvotes: 2