title: fopen c with multiple files
body: <p>In my software I have to read multiple txt databases in a serial way, so I read the first, then I do something with the info I got from that file, than I open another one to write and so on.</p>
  
  <p>Sometimes I got an error on an opening OR creation of a file, and then I got errors on all the following opening/creation, which uses different functions, different variables, different files.</p>
  
  <p>So for example I call the function below, which uses two files, and I got an error "* error while opening file -%s- ..\n", then all the other fopen() in my code goes wrong!</p>
  
  <p>This is an example of code for one single file:</p>
  
  <pre><code>FILE *filea;
  if((filea=fopen(databaseTmp, "rb"))==NULL) {
      printf("* error while opening file -%s- ..\n",databaseTmp);
      fclose (filea);
      printf("---------- createDatabaseBackup ----------\n");
      return -1;
  }
  int emptyFolder=1;
  FILE *fileb;
  if((fileb=fopen(databaseBackup, "ab"))==NULL) {
      printf("* error while opening file -%s- ..\n",databaseBackup);
      fclose (fileb);
      printf("---------- createDatabaseBackup ----------\n");
      return -1;
  }
  else {
      int i=0;
      char c[500]="";
      for (i=0;fgets(c,500,filea);i++) {
          fprintf(fileb,"%s",c);
          emptyFolder=0;
      }
  } 
  fclose(fileb);
  fclose(filea);
  </code></pre>