title: Copying a specific column of a file to another file in C
body: <p>I have two files, the first of which looks like this</p>
  
  <pre><code>125 6.678
  435 9.084
  234 8.874
  </code></pre>
  
  <p>and so on for about 2,048,000 entries, generated by my program. 
  The second file is a file generated by gnuplot and looks a bit like:</p>
  
  <pre><code>65 321456 985
  78 98374  834
  54 8493   848
  </code></pre>
  
  <p>and so on also for about 2,048,000 entries. </p>
  
  <p>Now what I need to do is to plot the second column of the first file and the two columns of the second file against each other with gnuplot in 3D. I think the first task is to put them all into the same file and I just want to write a simple c program that quickly reads both files and puts the relevant columns in one file but I'm not sure how to do it. I know how to copy the entire contents of a file and have them written to another file using a c program - for example to do this I have the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main (int argc, const char * argv[])
  {
  FILE *avalanche_size_BM;
  FILE *avalanche_size_BM_2000;
  char ch;
  
  
  avalanche_size_BM = fopen("/Users/maheensiddiqui/Documents/MSc_Proj/avalanche_size_BM.dat","r");
  
  if (avalanche_size_BM == NULL) 
  {
      printf("I couldn't open.\n");
      exit(0);
  }
  avalanche_size_BM_2000 = fopen("/Users/maheensiddiqui/Desktop/avalanche_size_BM_2000.dat", "w");
  if (avalanche_size_BM_2000 == NULL) 
  {
      printf("I couldn't open.\n");
      exit(0);
  }
  
  printf("\n success!!");
  
  while((ch=getc(avalanche_size_BM))!=EOF)
        putc(ch,avalanche_size_BM_2000);
  
  fclose(avalanche_size_BM);
  fclose(avalanche_size_BM_2000);
  
  
  
  return(0);
  }
  </code></pre>
  
  <p>But how exactly do I tell it to just read the second column in the first file and the first two columns in the second file and copy them (rather than all columns) to a third file which I can use to plot my 3-D plot.</p>
  
  <p>Any help will be much appreciated!</p>
  
  <p>Thank you</p>