On Feb 27, 8:51 pm, David Harmon <sou...@netcom.com> wrote:
> On 27 Feb 2007 20:25:44 -0800 in comp.lang.c++, "uche"
> <uraniumore...@hotmail.com> wrote,
>
> >On Feb 27, 8:00 pm, David Harmon <sou...@netcom.com> wrote:
> >> On 27 Feb 2007 19:53:33 -0800 in comp.lang.c++, "uche"
> >> <uraniumore...@hotmail.com> wrote,
>
> >> >This function that I have implemented gives me an infinite loop. I am
> >> ...
> >> > while (!endoffile)
>
> >> endoffile is never changed within the function posted, so of course you
> >> have either an infinite loop or no loop. What was supposed to change
> >> the value of endoffile?
>
the disk.eof(file_in); was supposed to change the value of the
endoffile variable..Here is the code for the eof class function...
#include "disk.h"
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
bool Cdisk:

pen(const char* filename, std::ifstream& file_in)
{
file_in.open(filename, ios::binary);
if (!file_in)
{
printf("Fail to Open\n");
return false;
}//if
return true;
}//open
bool Cdisk::eof(ifstream& file_in) const
{
if (file_in.eof())
return 1;
return 0;
}//eof
unsigned char Cdisk::read(unsigned char* buffer, std::ifstream&
file_in, int& current_buff_size, int& file_index)
{
if(current_buff_size <= 0)
{
file_in.read((char*)buffer, 512);
current_buff_size =file_in.gcount();
}
if(current_buff_size==0)
{
exit(0); //terminates the whole program!!
}
current_buff_size--;
file_index++;
return (buffer[file_index]);
}//read
int Cdisk::seek(int position, std::ifstream& file_in, Cdisk& disk)
{
int start(0), end(0);
start =disk.tell(file_in);
file_in.seekg(0, ios::end);
end =disk.tell(file_in);
int size_of_file = end - start;
file_in.seekg(0, ios::beg);
return size_of_file;
/*
long pos;
long file_beg, file_end;
long file_size;
pos = fseek(file_in, position, 0);
if (pos == 0 || pos <= 511)
return true;
return false;*/
}//seek
int Cdisk::tell(std::ifstream& file_in) const
{
int start = file_in.tellg();
return start;
}//tell
void Cdisk::close(std::ifstream& file_in)
{
file_in.close();
}//close
> >=================
> >Here is the 'main' code:
>
> But without _your_ answer to the above question "What was supposed to
> change the value of endoffile?", the loop is still endless.