blob: ac0bcc935239792529dd155f3762db8d287349bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#include <stdio.h>
int main()
{
FILE *fp; /* The file handle for input data */
fp=stdin;
int ch; /* Each character read. */
int checksum = 0; /* The checksum mod 2^16. */
int count=0;
printf("this will calc a simple checksum of the enered text\nPress Left Control + D to signify end of file \n",checksum,count);
while ((ch = getc(fp)) != EOF) {
checksum = (checksum >> 1) + ((checksum & 1) << 15);
checksum +=(int) ch;
checksum &= 0xffff; /* Keep it within bounds. */
count++;
}
printf("checksum : 0x%08X for %i bytes\n",checksum,count);
}
|