Hi,

I need to read all the records in a file till the end and print it to an outputfile.

So I used feof() -

while(feof(fp_infile) !=0)
{
fread(xxxx);
fread(xxxx);

fprintf(fp_outfile, XXXXX);
}

But this is not giving me any output i.e, the output file is empty.

Can anyone help??? Is the usage of feof() wrong??

jazz

1. do not use feof().
2. your program is mixing binary file read with text file writes. If the file is truly a binary file then simply using fprintf() to write it to another file is not what you want to do.

char buffer[255];
size_t nBytes;
while( (nBytes = fread(buffer,1,sizeof(buffer),fp_infile)) > 0)
{
    fwrite(buffer,1,nBytes,fp_outfile);
 }
fclose(fp_infile);
fclose(fp_outfile);