What does the X represent in the scanf format specifier %X.Yf?

  • Thread starter Thread starter Luongo
  • Start date Start date
  • Tags Tags
    Format
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
Luongo
Messages
119
Reaction score
0
C: Format Specifier "%f"

I understand the format specifier is a placeholder for a value to be calculated via scanf feature but I'm unsure of the notation %X.Yf
What does the X represent? i understand Y gives the number of spots after the decimal but i don't understand what the X portion does? Can you give a few examples?
Thanks
 
Physics news on Phys.org


Luongo said:
I understand the format specifier is a placeholder for a value to be calculated via scanf feature but I'm unsure of the notation %X.Yf
What does the X represent? i understand Y gives the number of spots after the decimal but i don't understand what the X portion does? Can you give a few examples?
Thanks

Do you mean scanf, or printf?

I don't like scanf, but that's a detail. In scanf, the Y doesn't mean anything; in fact I think it is an error to use .Y in a scanf format. The number of places is whatever you have in the input text.

The field width (X) is the maximum number of characters it will read for that "field". The specifics of where fields start and finish can be a bit subtle. Basically the floating point field in the input text end when you get to a character which is not part of the number, of once you've run out of the allowed field width, whichever comes sooner.

Cheers -- sylas