Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ffcccc
void do_stuff(void) {
   FILE *logfile = fopen("log", "a");
  if(logfile == NULL) {
    /* Checkhandle for errors, write logs pertaining to 
    *error */
  }

  /* Write logs pertaining to do_stuff(), etc */

  /* ... */
}

int main(void) {
  FILE /* Check for errors, write logs pertaining tologfile = fopen("log", "a");
  if(logfile == NULL) {
    /* main(), etc.handle error */
  }

 FILE /*logfile = fopen("log", "a");    Write logs pertaining to main() */

   do_stuff();

   /* ... */
}

However, the file log is opened twice simultaneously. The result is implementation-defined and potentially dangerous.

...

Code Block
bgColor#ccccff
void do_stuff(FILE *logfile) {
  /* Check for errors, write Write logs pertaining to do_stuff() */

   /* do_stuff, etc... */
}

int main(void) {
  FILE *logfile = fopen("log", "a");
  if(logfile == NULL) {
    /* Checkhandle for errors, write logs pertaining to 
   * main, etc.error */
  }

  /* Write logs pertaining to main() */

  do_stuff(logfile);

  /* ... */
}

...