title: Using write() system call to output dec/hex value of char array bufffer
body: <pre class="lang-c prettyprint-override"><code>int fd = open(argv[argc-1], O_RDONLY, 0);
   if (fd &gt;=0) {
     char buff[4096]; //should be better sized based on stat
     ssize_t readBytes;
     int j;
  
     readBytes = read(fd, buff, 4096);
  
     char out[4096];
     for (j=0; buff[j] != '\0'; j++) {
       out[j] = buff[j];
       //printf("%d ", out[j]);
     }
  
     write(STDOUT_FILENO, out, j+1);
  
     close(fd);
  }
   else {
     perror("File not opened.\n");
     exit(errno);
   }
  </code></pre>
  
  <p>This is code for a file dump program. The goal is to have a file and dump its contents to the command line both as ASCII chars and as hex/dec values. The current code is able to dump the ascii values, but not the hex/dec. We are allowed to use printf (as seen in the commented out section) but we can get extra credit if we don't use any high level (higher than system) functions. I have tried multiple ways to manipulate the char array in the loop, but it seems no matter how I try to add or cast the chars they come out as chars.</p>
  
  <p>This isn't surprising since I know chars are, at least in C, technically integers. I am at a loss for how to print the hex/dec value of a char using write() and as have yet not seen any answers on stack that don't default to printf() or putchar()</p>