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
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top