scanf

S

sulekhasweety

scanf(" \"%[^\"]\"",s); means

The scanf will expect a string enclosed within double quotes for
correctly reading the input. Within the double quotes it will accept
any input other than ". It will stop reading at the second "
character.

is this explanation correct..???
 
S

sulekhasweety

scanf(" \"%[^\"]\"",s); means
The scanf will expect a string enclosed within double quotes for
correctly reading the input. Within the double quotes it will accept
any input other than ". It will stop reading at the second "
character.
is this explanation correct..???

Almost. In addition to what you've described, the
scanf() will also read and discard white space (if any)
prior to the first quote mark.

STRONG recommendation: Use something like "%100["
instead of just "%[", to avoid re-inventing the hazards
of gets().

suppose if I change scanf(" \"%[^\"]\"",s); to

scanf("\"%[^\"]\"",s);

the scanf() won't read and discard white space (if any)
prior to the first quote mark. isn't it ?
 
R

Robert Gamble

scanf(" \"%[^\"]\"",s); means

The scanf will expect a string enclosed within double quotes for
correctly reading the input. Within the double quotes it will accept
any input other than ". It will stop reading at the second "
character.

is this explanation correct..???

In addition to Eric's comments, it is worth noting that the "%["
conversion specifier matches *one or more* characters so it will fail
if there are no characters between the quotes, i.e. "".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

scanf() 2
question about scanf 11
Scanf Problem 5
Help in this program. 2
question on assignment suppression in scanf 2
Only number input thru scanf() 8
Scanf question 4
scanf and loop 6

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,114
Latest member
GlucoPremiumReview
Top