as far as i can tell, this
while(!feof(pcxfile))
{
fread(&c, sizeof(char), 1, pcxfile);
size++;
if(size > 10000000)return;
}
includes the EOF, because it simply has not gotten to that when the char just before EOF is read. EOF gets read. and then feof(pcxfile) gets set
so your size would be incorrect by +1.
you could do this instead
while(fread(&c,sizeof(char),1, pcxfile))
{
if(size >MAX_FILE_SIZE)
return;
}
it will discontinue the while loop becuase EOF is NULL, and while(NULL) {dostuff} will not dostuff.
btw, i spend a great deal of time studing this for my TBL checker,
sinze i have to read in some 1 mb files.
i do however acces files like this
#include
#include //header for std::ifstream functions
using namespace std;//so i dont have to type std:: all the time
#include //header for usefull c++ type strings
using namespace std;
#include //header for simple output to screen, always much better than printf from ordinary C
somefunction()
{
ifstream myfile(*char)//opens the file
myfile.(AWHOLELOTOFUSEFULL-SUBFUNCTIONS)//mscv6.0 should auto show you the functions.
myfile.getline(aconstchar,READ_MAX,'\n')//terminate read on
encounter newline, and certainly if read_max has been reached
//and it dont care if it is a binary or textfile it is reading.
//also, strings are better than chars, since you dont have to deal with all the rules that ordinary C_strings has.
string mystring ="some words"
string mysecondstring =mystring.substr(6,5);
printf(mysecondstring);// would output "word"
//you can even do this
char[10] junk='1234567890';
mythirdstring = junk;
/*c++ strings auto expands, or contracts according to what they are being setting equal to. something ordinary c-style strings can´t
//no more the, cant convert char[n1] to char[n2] and so on.
why all this, well its always good to know the basics, but coding is moving towards C++, becuase it is more accesible, and decreases production time, you might as well learn c++, rather than punching c.-style stuff that is becomming obselete.