--- In [email protected], "izecksohn" <izecks...@...> wrote:
>
> --- "johnmatthews2000" <jm5678@> wrote:
> > 
> > 6. You need to check whether rebase_stats.txt exists before you attempt to 
> > read it, and create it if it doesn't. The current code returns EXIT_SUCCESS 
> > if it can't read it - should be EXIT_FAILURE?
> 
>   I applied you suggestion, but I do not know if it is a good idea as:

The following should work - the user doesn't need any special privileges:

  FILE *file_stats = fopen (filename, "r+");
  /* Attempt to open stats file. */
  if (!file_stats)
  {
    /* Failed - assume it doesn't exist, so try to create. */
    printf("creating %s\n", filename);
    if (!(file_stats = fopen(filename, "w+")))
    {
      fprintf (stderr, "I could not open %s\n%s\n", filename, strerror(errno));
      return EXIT_FAILURE;
    }
  }


Reply via email to