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

  • Thread starter Thread starter Luongo
  • Start date Start date
  • Tags Tags
    Format
AI Thread Summary
The discussion centers on the format specifier "%X.Yf" used in C programming, specifically in relation to the scanf function. The user seeks clarification on the meaning of the "X" in this notation, while already understanding that "Y" indicates the number of decimal places. It is clarified that in the context of scanf, "Y" is not applicable, as it does not influence input reading. Instead, "X" represents the maximum number of characters that can be read for that field. The floating-point input will stop when a non-numeric character is encountered or when the maximum field width is reached, whichever occurs first.
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
 
Technology 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
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top