title: How to use int16_t or int32_t with functions like scanf
body: <p>The way that I understand <code>int16_t</code> or <code>int32_t</code> in C is that they are typedefed to be 16 and 32 bit numbers respectively on your computer. I believe you would use these when you need to guarentee a number is 16 or 32 bits because different systems do not always represent an <code>int</code> as 32 bits or a <code>short</code> as 16 bits (Is this assumption correct? I find mixed answers when I look online.).</p>
  
  <p>My question is how would I use a function like <code>scanf</code> to get input from a user with a <code>int16_t</code> or a <code>int32_t</code> or any of the other typedefed number types when I require them to actually be 16 bits or 32 bits or whatever? Is there some sort of special string modifier? Normally if I wanted to get an <code>int</code> from a user without caring about how large it is actually represented as I would write something like this</p>
  
  <pre><code>scanf("%d", &amp;int);
  </code></pre>
  
  <p>This works if I pass in a <code>int32_t</code> but I assume it is only because an <code>int</code> on my system is 32 bits and it does not specifically give me a 32 bit number instead it just gives me an <code>int</code>. How would I go about getting number that is guarenteed to be 32 bits? I have looked on <a href="http://www.cplusplus.com/reference/cstdio/printf/" rel="noreferrer">this page of string modifiers</a> and a few other places but have found no mention of these typedefed number types. </p>
  
  <p><strong>Edit:</strong> Since receiving an answer to my question I have done some Googling and found <a href="http://www.nongnu.org/avr-libc/user-manual/group__avr__inttypes.html" rel="noreferrer">this</a>. I included it below for reference as well. </p>
  
  <pre><code>uppercase hexadecimal printf format for uintptr_t
  
  #define SCNd16   "d"
  decimal scanf format for int16_t
  
  #define SCNd32   "ld"
  decimal scanf format for int32_t
  
  #define SCNd8   "hhd"
  decimal scanf format for int8_t
  
  #define SCNdFAST16   "d"
  decimal scanf format for int_fast16_t
  
  #define SCNdFAST32   "ld"
  decimal scanf format for int_fast32_t
  
  #define SCNdFAST8   "hhd"
  decimal scanf format for int_fast8_t
  
  #define SCNdLEAST16   "d"
  decimal scanf format for int_least16_t
  
  #define SCNdLEAST32   "ld"
  decimal scanf format for int_least32_t
  
  #define SCNdLEAST8   "hhd"
  decimal scanf format for int_least8_t
  
  #define SCNdPTR   SCNd16
  decimal scanf format for intptr_t
  
  #define SCNi16   "i"
  generic-integer scanf format for int16_t
  
  #define SCNi32   "li"
  generic-integer scanf format for int32_t
  
  #define SCNi8   "hhi"
  generic-integer scanf format for int8_t
  
  #define SCNiFAST16   "i"
  generic-integer scanf format for int_fast16_t
  
  #define SCNiFAST32   "li"
  generic-integer scanf format for int_fast32_t
  
  #define SCNiFAST8   "hhi"
  generic-integer scanf format for int_fast8_t
  
  #define SCNiLEAST16   "i"
  generic-integer scanf format for int_least16_t
  
  #define SCNiLEAST32   "li"
  generic-integer scanf format for int_least32_t
  
  #define SCNiLEAST8   "hhi"
  generic-integer scanf format for int_least8_t
  
  #define SCNiPTR   SCNi16
  generic-integer scanf format for intptr_t
  
  #define SCNo16   "o"
  octal scanf format for uint16_t
  
  #define SCNo32   "lo"
  octal scanf format for uint32_t
  
  #define SCNo8   "hho"
  octal scanf format for uint8_t
  
  #define SCNoFAST16   "o"
  octal scanf format for uint_fast16_t
  
  #define SCNoFAST32   "lo"
  octal scanf format for uint_fast32_t
  
  #define SCNoFAST8   "hho"
  octal scanf format for uint_fast8_t
  
  #define SCNoLEAST16   "o"
  octal scanf format for uint_least16_t
  
  #define SCNoLEAST32   "lo"
  octal scanf format for uint_least32_t
  
  #define SCNoLEAST8   "hho"
  octal scanf format for uint_least8_t
  
  #define SCNoPTR   SCNo16
  octal scanf format for uintptr_t
  
  #define SCNu16   "u"
  decimal scanf format for uint16_t
  
  #define SCNu32   "lu"
  decimal scanf format for uint32_t
  
  #define SCNu8   "hhu"
  decimal scanf format for uint8_t
  
  #define SCNuFAST16   "u"
  decimal scanf format for uint_fast16_t
  
  #define SCNuFAST32   "lu"
  decimal scanf format for uint_fast32_t
  
  #define SCNuFAST8   "hhu"
  decimal scanf format for uint_fast8_t
  
  #define SCNuLEAST16   "u"
  decimal scanf format for uint_least16_t
  
  #define SCNuLEAST32   "lu"
  decimal scanf format for uint_least32_t
  
  #define SCNuLEAST8   "hhu"
  decimal scanf format for uint_least8_t
  
  #define SCNuPTR   SCNu16
  decimal scanf format for uintptr_t
  
  #define SCNx16   "x"
  hexadecimal scanf format for uint16_t
  
  #define SCNx32   "lx"
  hexadecimal scanf format for uint32_t
  
  #define SCNx8   "hhx"
  hexadecimal scanf format for uint8_t
  
  #define SCNxFAST16   "x"
  hexadecimal scanf format for uint_fast16_t
  
  #define SCNxFAST32   "lx"
  hexadecimal scanf format for uint_fast32_t
  
  #define SCNxFAST8   "hhx"
  hexadecimal scanf format for uint_fast8_t
  
  #define SCNxLEAST16   "x"
  hexadecimal scanf format for uint_least16_t
  
  #define SCNxLEAST32   "lx"
  hexadecimal scanf format for uint_least32_t
  
  #define SCNxLEAST8   "hhx"
  hexadecimal scanf format for uint_least8_t
  
  #define SCNxPTR   SCNx16
  hexadecimal scanf format for uintptr_t
  </code></pre>