title: C write and read single character
body: <p>I'm currently working with processes, and encountered a problem while reading and writing char to a file.</p>
  <p>The idea is we have couple of processes which should <strong>read an integer</strong> from file, <strong>increment it</strong> and <strong>write</strong> back. Here is my attempt: (i wont include error checking)</p>
  <pre><code>...
  char n;
  char buff[5];
  int number;
  ...
  read(my_desc, &amp;n, 1);
  number = (int)n;
  number++;
  sprintf(buff, &quot;%4d&quot;, number);
  write(my_desc, buff, sizeof(buff));
  ...
  </code></pre>
  <p>The file is just plain</p>
  <blockquote>
  <p>0</p>
  </blockquote>
  <p>But the output seems to be not correct (almost always garbage).</p>
  <p>I already read write and read manuals but im clueless. I've checked some topics on read and write functions here on stack overflow, but most of them either don't work for me or i struggle with implementation.</p>
  <p>Thanks in advance.</p>