I try to calculate the checksum of the file in c.
I have a file of around 100MB random and I want to calculate the checksum.
I try this code from here: https://stackoverflow.com/a/3464166/14888108
int CheckSumCalc(char * filename){
FILE *fp = fopen(filename,"rb");
unsigned char checksum = 0;
while (!feof(fp) && !ferror(fp)) {
checksum ^= fgetc(fp);
}
fclose(fp);
return checksum;
}
but I got a Segmentation fault. in this line "while (!feof(fp) && !ferror(fp))"
Any help will be appreciated.