Read ints from a binary file that has 2560 numbers in it
Code:
#include <stdio.h>
int main(void)
{
FILE *fp;
int foo[10];
int i;
if ((fp = fopen("xyz.set", "rb")) == NULL) {
puts("Error: Input file invalid");
return -1;
} else {
for (i = 0; i < 10; i+=5) {
fread(&foo[i], sizeof(int), 5, fp);
}
}
fclose(fp);
for (i = 0; i < 10; i++) {
printf("%d ", foo[i]);
}
putchar('\n');
return 0;
}
I need to read in a file that has binary ints of 4 bytes (2560 total ints) each and i'm stuck with the above code. Any help will be appreciated. Thanks