27 lines
435 B
C
27 lines
435 B
C
|
#include <fcntl.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdio.h>
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
int fd;
|
||
|
unsigned char tally = 0;
|
||
|
unsigned char next = 0;
|
||
|
if (argc!=2) return -1;
|
||
|
|
||
|
fd = open(argv[1], O_RDWR|O_APPEND);
|
||
|
if (fd<0) return -2;
|
||
|
|
||
|
while (read(fd, &next, 1)) {
|
||
|
//printf("Tally: %X, next byte: %X\n", tally, next);
|
||
|
tally ^= next;
|
||
|
};
|
||
|
|
||
|
printf("Final tally: %X\n", tally);
|
||
|
|
||
|
write(fd, &tally, 1);
|
||
|
|
||
|
close(fd);
|
||
|
return 0;
|
||
|
}
|