title: copy a text file using c
body: <p>What I want to do for now is have an input text file, load its content into a 2d array, perform something on it and then put it out into another file. Essential problem for me is keeping the original files' structure. This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void)
   {
    FILE *ifp, *ofp;
    char buffer[100];
    int i, c;
  
    ifp=fopen("test.in", "r");
    ofp=fopen("test.out", "w");
  
    while (!feof(ifp)){
    if(fscanf(ifp, "%s", buffer) != 1)
     break;
    fprintf(ofp, "%s", buffer); 
  }  
  return 0;
  }
  </code></pre>
  
  <p>my input:</p>
  
  <pre><code>aaa bb bbb
  bbbbb bbbb aa
  </code></pre>
  
  <p>and output:</p>
  
  <pre><code>aaabbbbbbbbbbbbbbaa
  </code></pre>
  
  <p>Everything I tried for EOL or EOF recognition caused infinite loops. Performing anything with     "%c" instead of     "%s" resulted in worse outputs. Thanks in advance.
  edit: I'm aware I can get the output to be words with spaces between them or have every word in a new line but I don't know how to get from here to final result.</p>