home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / OS2OMMM.SRC / CRC.C < prev    next >
C/C++ Source or Header  |  1989-02-13  |  755b  |  41 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <crc.h>
  4.  
  5. /*
  6.     this program and source code are completely public-domain.  crc
  7.     routines are from the rzsz source code by Chuck Forsberg
  8.  
  9.     updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
  10. */
  11.  
  12. void main(int argc, char *argv[])
  13.  
  14. {
  15.     FILE *fp;
  16.     unsigned int crc = 0;
  17.     unsigned int ch = 0;
  18.     
  19.     
  20.     if (argc < 2) {
  21.         fputs("crc by jim nutt\nneed a filename\n.",stderr);
  22.         exit(1);
  23.     }
  24.  
  25.     if ((fp = fopen(argv[1],"rb")) == NULL) {
  26.         fputs("crc by jim nutt\nfile does not exist\n.",stderr);
  27.         exit(1);
  28.     }
  29.  
  30.     while (!feof(fp)) {
  31.         fread(&ch,1,1,fp);
  32.         crc = updcrc(ch,crc);
  33.     }
  34.  
  35.     fclose(fp);
  36.     printf("the 16 bit CRC of %s is %x\n",argv[1],crc);
  37.     exit(0);
  38. }
  39.     
  40.   
  41.