title: Read and write bytes in C (from/in file)
body: <p>I have to solve the following problem in <strong>C</strong> for the operating systems class:</p>
  
  <p>At the command line three file are given, two for input, one for output.
  The output file is obtained from input files, as follows: 10 bytes from
  the first file, 20 bytes from the second file, next 10  bytes from the
  first file, next 20 bytes from the second file and so on, until
  an input file is finished.</p>
  
  <p>Simple but inefficient solution: read and write groups of 10 / 20 bytes.
  An efficient (but not simple) solution: read and write blocks
  with 5000 bytes.</p>
  
  <p>I tried this for the simple solution. But it doesn't work... Can anyone help me?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main(int argc, char* argv[], char* envp[]){
  if (argc != 4){
      printf("%s", "Usage: c4h filename\n");
      return 0;
  }
  
  int c1,c2,i;
  FILE *in1;
  FILE *in2;
  FILE *out;
  
  in1 = fopen(argv[1], "r");
  in2 = fopen(argv[2], "r");
  out = fopen(argw[3], "wb");
  
  
  if (in1 == NULL){
      printf("%s", "File not found!\n");
      return 0;
  }
  
  if (in2 == NULL){
      printf("%s", "File not found!\n");
      return 0;
  }
  
  while(feof(in1)!=0 &amp;&amp; feof(in2)!=0){
      for(int i=0;i&lt;20;i++)
          if(feof(in1)!=0){
              c1 = fgetc(in1);
              fputc(c1,out);
          }
  
      for(int i=0;i&lt;10;i++){
          if(feof(in2)!=0){
              c2 = fgetc(in2);
              fputc(c2,out);
          }
  
  }
  
  fclose(in1);
  fclose(in2);
  fclose(out);
  return 0;
  }
  </code></pre>