title: Copying contents of a file to another using read(), write(), open()
body: <p>I whipped up a quick program to simply grab the contents of a file and transpose them onto an output file. The first time I run my program I get no errors and it looks as if everything is going to work fine. However, when I check my output file there is nothing in the file. My first thought was that the permissions were not correct and writing was not allowed. When I manually created a .txt file in the directory and set the permissions and then ran the program on that it seemed to work (ubuntu is showing me the contents of the file, the copy) but I can't open the actual file. 
  Hopefully someone with more experience than myself can help me out. 
  Well here is my code:</p>
  
  <pre><code>int main(int argc, char* argv[]){
    char buf[128];
    int outft, inft,fileread;
    // output file opened or created
    if((outft = open(argv[1], O_CREAT | O_APPEND | O_RDWR))==-1){
      perror("open");
    }
    // lets open the input file
    inft = open(argv[2], O_RDONLY);
    if(inft &gt;0){ // there are things to read from the input
      fileread = read(inft, buf, 160);
      printf("%s\n", buf);
      write(outft, buf, 160);
      close(inft);
    }
    close(outft);
    return 0;
  }
  </code></pre>