my program keeps hanging up when I try to fill this array of objects of an ADT I created. maybe you guys can dig through this code a little and help me:
the function: the point is to dig through an input file and fill an array of type TimeCard. I open the file in my main program, but that's not where the problem is. It seems too long and complicated for some reason
Code:
void TimeCardList::fill (ifstream& inf)
{
const int NUM_EMPLOYEES = 20;
const int MAX_ID = 5;
const int MAX_TIME = 3;
int n, index;
char id[MAX_ID];
char time[MAX_TIME];
char next;
inf.get(next);
for (int i = 0; i < NUM_EMPLOYEES; i++)
{
index = 0;
while (next != ' ')
{
if ((isdigit(next)) && (index < MAX_ID))
{
id[index] = next;
index++;
}
inf.get(next);
}
id[index] = '\0';
n = atoi (id);
cards[i].set_id(n);
inf.get(next);
inf.get(next);
//two more while loops with about the same code
do //do loop gets a new line once I've read in
{
inf.get(next);
}while (next != '\n');
the class: there are two classes, one is for a single time card that has variables for the employee's ID number and hour and minute variables for how long he's worked. the definition looks like this:
Code:
class TimeCard
{
public:
TimeCard();
void set_id(int d);
void set_hrs(int h);
void set_min(int m);
int get_id();
int get_hrs();
int get_min();
void print (ostream& outf);
private:
int id, hrs, min;
};
here's the other class, it's designed to hold an array of TimeCard objects:
Code:
class TimeCardList
{
public:
void fill (ifstream& inf);
void sort();
TimeCard search();
TimeCard cards[100];
};
it's not finished, the fill function is the only one I'm working on right now
the input file looks like this:
Code:
1010 10:10
4011 11:40
1205 05:20
I get no compiler or runtime errors, just when I run the program nothing happens and I have to exit it. I don't even know what it's doing while it's hanging there. I know the file is opening because I tested it with a cout.
help me please