There are a few things that could go wrong here.
Firstly, no this line, memory allocation can fail. (Malloc can return a NULL pointer, you should check this. (You should also check that the file opened without error.)
char *buf = malloc(7008991);
Next, in the loop. Remember that fgets reads one line, regardless of how long that is, up to a maximum of 1024-1 bytes (and appends a null-character). Please not that for binary input, using fread
is probably more appropriate.
while(fgets(buf+i, 1024, fp)) {
After that, this is a good line, as you really do not know how long a line is.
i+=strlen(buf);
This line however is probably why you are failing.
if(i==7008991)break;
You are requireing the size to be exactly 77008991 bytes long to break. That is rather unlikely unless you are very very sure about the formatting of your file. This line should probably read if ( i >= 7008991 ) break;
You should probably replace your explicit size with a named constant as well.