title: Using scanf for reading an unsigned char
body: <p>I'm trying to use this code to read values between 0 to 255 (<code>unsigned char</code>). </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main(void)
  {
      unsigned char value;
  
      /* To read the numbers between 0 to 255 */
      printf("Please enter a number between 0 and 255 \n");
      scanf("%u",&amp;value);
      printf("The value is %u \n",value);
  
      return 0;
  }
  </code></pre>
  
  <p>I do get the following compiler warning as expected.</p>
  
  <pre>
  warning: format ‘%u’ expects type ‘unsigned int *’, but argument 2 has type ‘unsigned char *’
  </pre>
  
  <p>And this is my output for this program.</p>
  
  <pre>
  Please enter a number between 0 and 255
  45
  The value is 45 
  Segmentation fault
  </pre>
  
  <p>I do get the segmentation fault while running this code. </p>
  
  <p><strong>What is the best way to read <code>unsigned char</code> values using <code>scanf</code>?</strong>  </p>