hi,
im processing a binary file which contains 1,249,820 data points, and since the size of the file is 1,249,820 bytes, im assuming each data point uses 1 byte of memory. basically, im running through every point, and which ever point that is >= 50, i will set that point to 0 (each point runs from 0-255). so i hav written sth like
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
FILE *fp3;
fp3 = fopen("xxx\\b3", "rb");
FILE *fp3_o;
fp3_o = fopen("xxx\\b3_o", "wb");
long int i, size = 1249820;
char *b3_dn = malloc(size * sizeof(char));
fread(b3_dn, sizeof(char), size, fp3);
for (i=0; i<size; i++){
if(b3_dn[i] >= 50) b3_dn[i] = 0;
}
fwrite(b3_dn, sizeof(char), size, fp3_o);
free(b3_dn);
return 0;
}
when i run it, however, the results are not wat i expect, ie the values which are >= 50 remain unchanged, many values <50 become 0, and basically values are randomly changed to 0 all over. can someone help?
btw, char takes 1 byte and int takes 4 byte on my system.