//you can read the data once, use the while(1) and judge the eof and error
#include <stdio.h>
#include <string.h>
#include <strings.h>
int main(int arge, char **argv)
{
int SIZE = 1024, NMEMB = 4;
char read_data[1920*1020*3] = {0};
char tmp[1024*4] = {0};
unsigned long int ret_size = 0;
long post1 = 0, post2 = 0;
long total;
FILE *pFile = NULL;
pFile = fopen(argv[1], "r");
if(pFile)
{
while (1)
{
bzero(tmp, sizeof (tmp));
post1 = ftell(pFile);
ret_size = fread(tmp, SIZE, NMEMB, pFile);
if(ret_size < NMEMB)//error or eof
{
if(feof(pFile))
{
printf("eof\n");
strncpy(read_data+post1, tmp, sizeof (read_data)-total);
post2 = ftell(pFile);
total += (post2-post1);
break;
}
else if (ferror(pFile))
{
perror("fread()");
break;
}
}
strncpy(read_data+post1, tmp, sizeof (read_data)-total);
total += SIZE*NMEMB;
}
fclose(pFile);
}
else
{
perror("open error\n");
}
printf("read the file data size:%d\n", total);
return 0;
}