title: Extract a column of a list from a text file in C
body: <p>This may be a simple question with a straightforward answer, but searching through the site I didn't find anything (maybe because I'm new to C programming) except for python codes, which I already wrote and it's quite inefficient.</p>
  
  <p>Suppose I have a list of data in a <code>timestamps.txt</code> file, formatted like this:</p>
  
  <pre><code>&lt;large integer&gt;, &lt;integer between 1 and 8&gt;
  &lt;large integer&gt;, &lt;integer between 1 and 8&gt;
  </code></pre>
  
  <p>and so on (the file is about 4GB)...</p>
  
  <p>What I want to do is to copy only the second column to another file, say <code>singles.txt</code>.</p>
  
  <p>What I did so far works, but it's a rather naive approach and takes too much time. Here's my code:</p>
  
  <pre><code>int main(int argc, char const *argv[])
  {
      FILE *input_file;
      FILE *output_file;
      char ch;
      int check = 0;
  
      input_file = fopen("timestamps.txt","r");
      output_file = fopen("singles.dat","w");
      if (!input_file)
          return -1;
  
      while((ch = getc(input_file))!=EOF)
          {
  
              if(check==1)
                  {putc(ch,output_file);putc('\n',output_file);}
  
              if(ch == ',')
                  check = 2;
              else
                  check -= 1;
  
          }
  
  
      fclose(input_file);
      fclose(output_file);
  
      return 0;
  }
  </code></pre>
  
  <p>I'm sure there is a faster way, but I can't seem to make anything work.
  Any help would be much appreciated.</p>