Y
yexiangmo
I am facing a very weird problem of fread in VC6.0.
I have a binary file and use following testing code try to read in as
bytes
It works correctly in Linux and the final statement show the right
number
of bytes the program read in.
However, exact same code runs on windows read only few bytes and
thinks it reach the end of file. Do I miss something when I use fread
in windows?
Any idea can share?
Thanks.
Mark
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <math.h>
int main(int argc, char** argv)
{
int numBytes = 0;
char junk[1];
FILE *fpin = fopen( argv[1], "r+t");
if(fpin == NULL)
{
fprintf(stderr, "Cannot open file %s \n", argv[1]);
perror("Input file open failed\n");
return -1;
}
printf("file name is %s\n", argv[1]);
while(!feof(fpin))
{
if(fread(junk,1,1, fpin) == 1)
numBytes++;
}
printf("EOF reached after %d bytes read in!!!\n", numBytes);
return 0;
}
I have a binary file and use following testing code try to read in as
bytes
It works correctly in Linux and the final statement show the right
number
of bytes the program read in.
However, exact same code runs on windows read only few bytes and
thinks it reach the end of file. Do I miss something when I use fread
in windows?
Any idea can share?
Thanks.
Mark
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <math.h>
int main(int argc, char** argv)
{
int numBytes = 0;
char junk[1];
FILE *fpin = fopen( argv[1], "r+t");
if(fpin == NULL)
{
fprintf(stderr, "Cannot open file %s \n", argv[1]);
perror("Input file open failed\n");
return -1;
}
printf("file name is %s\n", argv[1]);
while(!feof(fpin))
{
if(fread(junk,1,1, fpin) == 1)
numBytes++;
}
printf("EOF reached after %d bytes read in!!!\n", numBytes);
return 0;
}