home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / R_LA4_02.ZIP / CHARCNT2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-31  |  872 b   |  34 lines

  1. /* CHARCNT2.C - From page 444 of "Microsoft C Programming for   */
  2. /* the IBM" by Robert Lafore. This file counts characters in    */
  3. /* a file that is opened as a binary file as opposed to a file  */
  4. /* opened as a text mode file. These 2 modes differ in the      */
  5. /* way they handle the EOF and the CR/LF-newline.               */
  6. /****************************************************************/
  7.  
  8. #include <stdio.h>
  9.  
  10. main(argc, argv)
  11. int argc;
  12. char *argv[];
  13. {
  14. FILE *fptr;
  15. char string[81];
  16. int count = 0;
  17.  
  18.    if(argc != 2) {
  19.       printf("\nFormat: C>charcnt2 filename");
  20.       exit();
  21.    }
  22.    if((fptr = fopen(argv[1], "rb")) == NULL) {
  23.       printf("\nCan't open file %s.", argv[1]);
  24.       exit();
  25.    }
  26.    while(getc(fptr) != EOF)
  27.       count++;
  28.    fclose(fptr);
  29.    printf("\nFile %s contains %d characters.", argv[1], count);
  30. }
  31.  
  32.  
  33.  
  34.