title: file contents modified on end of execution
body: <p>I am developing a utility which scans multiple text files, extracts relevant text and dumps it into another text file.</p>
  
  <pre><code>int main()
  {
      // file I/O code
      node *temp1;
     char script[255],segName[255],ch;
     char *dev;
     FILE *fp;
     int i=0;
     void removeSpace();
  
     dev=getenv("DEVSET");
     devset = atoi(dev);
     //clearing the file before starting
     fp=fopen("output.txt","w");
     fclose(fp);
  
     memset(script,'\0',sizeof(script));
     strcpy(script,"main"); // start with main
     head=createNode(script); // head is a global node*
     head-&gt;prev=NULL;
     head-&gt;next=NULL;
     temp1 = head;
  
     while(temp1 !=NULL)
     {
  
  
         read(temp1, script);// reads the text file corresponding to temp1 and   returns relevant data
  
         memset(segName,'\0',sizeof(segName));
         if (strcmp((temp1-&gt;name),"main"))
         {
             //if not main, start on a new line
             segName[0]='\n';
         }
  
  
         if (strcmp(script,"EOF")== 0 || strcmp(script,"")== 0 )
         {
             // end of file or Call not found
             temp1 = pop(head);
  
         }
         else
         {
             if (strcmp(script,"exit_flow") == 0)
             {
  
                 fp=fopen("output.txt","a");
  
                 fprintf(fp,"//FNF");
                 fclose(fp);
  
                 temp1=pop(head);
  
             }
             else
             {
                //Call found
  
                for(i=0;i&lt;script_index;i++) // script index is a global int
                {
                    strcat(segName,"-"); // no of dashes indicate depth of the call
                }
  
                strcat(segName,"&lt;");
                i=strlen(segName);
                segName[i]=call_type;
                strcat(segName,"&gt;");
                strcat(segName,(script));
  
                fp=fopen("output.txt","a");
                fprintf(fp,segName);
                fclose(fp);
                script_index++;
                temp1=createNode(script);
                push(head,temp1);
             }
         }
     }// end of while
  
     // Adjustment to remove extra spaces from the file
     removeSpace();
     fclose(fp);
      if(!devset)
          printf("\nExecution complete");
  
      printf("\nResult dumped to \"output.txt\"");
  
      printf("\nOpen the output file? ");
      fflush(stdin);
  
      ch=getchar();
      if (ch == 'y' || ch == 'Y')
      {
          system("notepad output.txt");// Text file displayed has correct data here
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Mentioned above is a part main().</p>
  
  <p>How much ever it may seem improbable, the contents of the file are modified after execution of the 'system' statement.
  A string(not exactly random) gets appended to the text file, although I have closed the file prior to the execution of 'system'.</p>
  
  <blockquote>
    <p>Environment - windows</p>
    
    <p>IDE- Code::Blocks</p>
    
    <p>Compiler - MinGW</p>
  </blockquote>
  
  <p>Is this because I haven't flushed some buffer?</p>