Try using the "%h"
modifier:
scanf("%hu", &length);
^
ISO/IEC 9899:201x – 7.21.6.1-7
Specifies that a following d , i , o , u , x , X , or n conversion
specifier applies to an argument with type pointer to short or
unsigned short.
More Related Contents:
- How do you type something on the same line of text in C [closed]
- C program goes into infinite loop with scanf [duplicate]
- Disadvantages of scanf
- How to use sscanf in loops?
- Why does scanf ask twice for input when there’s a newline at the end of the format string?
- Simple C scanf does not work? [duplicate]
- C: Multiple scanf’s, when I enter in a value for one scanf it skips the second scanf [duplicate]
- When should I use ampersand with scanf()
- scanf: “%[^\n]” skips the 2nd input but ” %[^\n]” does not. why?
- What does space in scanf mean? [duplicate]
- Reading a line using scanf() not good?
- What will happen if ‘&’ is not put in a ‘scanf’ statement?
- Does scanf() take ‘\n’ as input leftover from previous scanf()?
- printf not printing on console
- Going through a text file line by line in C
- difference between %ms and %s scanf
- Reading a single character in C
- What does `scanf(“%*[^\n]%*c”)` mean?
- Max string length using scanf -> ANSI C
- Get scanf to quit when it reads a newline?
- C – trying to read a single char from stdin (and failing) w/ scanf / getchar
- scanf(“%c”) call seems to be skipped
- Wrong format specifiers in scanf (or) printf
- C: How can I make it so scanf() input has one of two formats?
- Strange character after an array of characters
- While-loop ignores scanf the second time
- Using scanf and fgets in the same program?
- What are scanf(“%*s”) and scanf(“%*d”) format identifiers?
- Difference between scanf() and fgets()
- Getting multiple values with scanf()