0
Question related to inputs in C language
What can I use or do to take specific size of input for example if I want to take date as input than we know for days range will the (1 - 31) 5 bits will be enough similarly for months range is (1-12) 4 bits are enough and in the end lets say I want to save 128 years of range for that 7 bits are enough. Which function or is there any function I can use ?
1 ответ
+ 3
I think you are asking about how to implement bit fields and take input into them. Bit fields are used in structs, where you can define a custom type to have an arbitrary number of bits.
https://www.tutorialspoint.com/cprogramming/c_bit_fields.htm
According to this discussion, you cannot input directly into a bit field because it does not align with an address. You have to input to a temporary variable and then copy the value into the struct member.
https://stackoverflow.com/questions/68820520/scanf-input-for-structs-bitfields-in-c