title: File read write to same file?
body: <p>I've managed to open a file and read while writing to another file with <code>var=fopen(file,"r")</code> / <code>"w"</code> but even with r+ or w+ moded I can't open a file and alter its contents.</p>
  
  <p>Imagine this:</p>
  
  <pre><code>int formatacao (char original[]){/*se a cadeia nao tiver escrita em maiusculas, esta funçao vai alteralas para tal*/
      int val1;
      FILE * original_open;
  
      original_open = fopen (original,"r+");
  
      if (original_open==0){
         printf ("ficheiro %c 1.",original);
      }
  
  
      while ((val1=fgetc(original_open))!=EOF){
            if (val1&gt;='a'&amp;&amp;val1&lt;='z'&amp;&amp;val1){
               fputc(val1-32,original_open);
            }
            else 
            fputc(val1,original_open);
      }
  
      fclose (original_open);
      return (0);
  }
  </code></pre>
  
  <p>Code works, no errors, no warning, only problem is: it erases the contents on the file if I use it like this BUT this works:</p>
  
  <pre><code>int main (){
      int val1,val2,nr=0;
      FILE* fp1;
      FILE* fp2;
      fp1=fopen ("DNAexample.txt","r");
      fp2=fopen ("DNAexample1.txt","w");
      if (fp1==0){
         printf ("EPIC FAIL no 1.\n");
      }
      while ((val1=fgetc(fp1))!=EOF){
            if (val1&gt;='a'&amp;&amp;val1&lt;='z'&amp;&amp;val1){
               fputc(val1-32,fp2);
            }
            else 
            fputc(val1,fp2);
      }
  
  
      fclose (fp1);
      fclose (fp2);
      return (0);
  }
  </code></pre>
  
  <p>Flawlessly! How can I open a file, read char by char and decide if I want to change the char or not?</p>