home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
misc
/
volume28
/
crc16
/
part01
/
crc.c
next >
Wrap
C/C++ Source or Header
|
1992-03-15
|
1KB
|
43 lines
/* The following routines can be used to interpret the crc_table.
First use init_crc; then add_crc for each character, from
first to last; and finally, as report_crc to yield the
result. It is probably much more convenient to code these
routines inline; this file serves primarily as documentation. */
#include <stdio.h>
#include "crc_tab.h"
static unsigned short crc;
void init_crc(){crc = 0;}
void add_crc(c) unsigned char c;
{crc = crc_table[(crc & 0x00ff) ^ c] ^ (crc >> 8);
}
unsigned short report_crc(){return crc;}
void crcfile(name)char *name;
{FILE *f; int c; unsigned short ck;
printf("crc %s ", name);
f = fopen(name, "rb");
if(! f){printf("cannot find %s\n", name); return;}
init_crc();
while((c = getc(f)) >= 0){add_crc(c);}
ck = report_crc();
#ifdef AMIGA
printf("0x%x %d\n", ck, ck);
#else
printf("%#.4x %d\n", ck, ck);
#endif
fclose(f);
return;
}
void main(argc, argv)int argc; char *argv[];
{int i; char **c;
if(argc < 2){printf("crc filenames\n"); exit(1);}
c = &(argv[1]); i=argc;
while(--i)crcfile(*c++);
exit(0);
}