Feb 27, 2011 at 12:02am UTC
also is EOF 1A like it is in assembly using windows?
Feb 27, 2011 at 12:11am UTC
For your first question:
http://www.cplusplus.com/forum/windows/10853/
EOF is usually -1, but your best best is to use std::fstream::good() (C++ I/O) or ferror() (C I/O) or to compare it with the macro EOF (defined in stdio.h/cstdio).
Last edited on Feb 27, 2011 at 12:12am UTC
Feb 27, 2011 at 12:40am UTC
Let me explain more I want to make a program that reads in four bytes at a time and I need to test to see while fileRemaining(in bytes) >3
Last edited on Feb 27, 2011 at 1:18am UTC
Feb 27, 2011 at 2:08pm UTC
Well, using fseek/ftell/rewind every four bytes would be slow, you could try something like:
1 2 3 4 5 6 7 8 9 10 11 12 13
size_t file_remaining(FILE* stream, size_t read)
{
static size_t size = 0;
if (!(size)) {
fseek(stream, SEEK_END, 0);
size = ftell(stream);
rewind(stream);
} else {
size -= read;
}
return size;
}
Usage:
1 2 3 4 5 6 7
FILE* file = fopen("myfile.txt" , "r" );
size_t read = 0;
size_t buffersize = file_remaining(file, 0);
char * buffer = malloc(buffersize);
while (file_remaining(file, read))
read += fread(buffer, 1, buffersize, file);
Last edited on Feb 27, 2011 at 5:29pm UTC
Feb 28, 2011 at 8:28pm UTC
is the EOF counted as a byte when I read in? I don't want it to be counted if it is.
Last edited on Feb 28, 2011 at 8:28pm UTC