title: How does C read bytes using the read syscall?
body: <p>I need to read an <code>unsigned short</code> using the <code>read</code> system call.
  According to <a href="http://man7.org/linux/man-pages/man2/read.2.html" rel="nofollow noreferrer">the manpage</a>:</p>
  
  <blockquote>
    <p>read() attempts to read up to <code>count</code> bytes from file descriptor <code>fd</code>
           into the buffer starting at <code>buf</code>.</p>
  </blockquote>
  
  <p>In my case, an <code>unsigned short</code> is two bytes size, so it can store the numbers up to 65535. But when I execute this code:</p>
  
  <pre><code>char buf[2];
  bytes_read = read(0, buf, 2);
  bytes_wrote = write(1, buf, 2);
  </code></pre>
  
  <p>and type in the command line, say, the number <code>123</code>, it returns only <code>12</code>. Does it not read bytes, but symbols? How can I read a value with more than 2 symbols into a 2-byte buffer? For example, the maximum values of an <code>unsigned short</code>. I found nothing in either K&amp;R or the manpages about it, so I think it's very simple.</p>