FILE * fp;
int page_size=4;
size_t read=0;
char * buffer = (char *)malloc((page_size+1)*sizeof(char));
fp = fopen("example.txt", "rb"); //open the file for binary input
//loop through the file reading a page at a time
do
{
read = fread(buffer,sizeof(char),page_size, fp); //issue the read call
if (read > 0) //if return value is > 0
{
buffer[page_size]='\0';
printf("|%s|\n",buffer);
}
}
while(read == page_size); //end when a read returned fewer items
fclose(fp);
you can try with this code, this code is running fine.
I tried with your code and that is also running fine on my system.