Listing 3 Copies binary files

/* copy5.c */

#include <stdio.h>
#include <stdlib.h>

main(int argc, char *argv[])
{
   if (argc == 3)
   {
      char buf[BUFSIZ];
      FILE *inf, *outf;

      if ((inf = fopen(argv[1],"rb")) == NULL)
          return EXIT_FAILURE;

      if ((outf = fopen(argv[2],"wb")) == NULL)
          return EXIT_FAILURE;

      while (!feof(inf))
      {
          int nitems = fread(buf,1,BUFSIZ,inf);
          if (fwrite(buf,1,nitems,outf) != nitems)
              return EXIT_FAILURE;
      }

      fclose(inf);
      fclose(outf);
      return EXIT_SUCCESS;
   }
   else
      return EXIT_FAILURE;
}

/* End of File */