OK, well I thought I had fixed the problem but I dont think I did. I am having trouble correctly allocating space I think. What should I be doing?? I am totally clueless about how to work with this. some help would be appreciated!!!
CODE
const int MAX_NUMBERS = 50;
struct SimpleRecord
{
char *fName;
char *lName;
int id[MAX_NUMBERS];
float payRate;
float hours;
};
typedef SimpleRecord * ptrToRecord;
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include "Record.h"
using namespace std;
char* getFile();
void Sort( int [], int);
int search( int[], int, int);
void getID(int [], int);
void setId( SimpleRecord&, int );
int getId( SimpleRecord );
int main()
{
SimpleRecord * bob;
bob = new SimpleRecord[50];
int count=0;
fstream infile;
char* filename;
filename = getFile();
infile.open( filename );
if(!infile)
{
cout<<"ERROR:" << endl;
return 1;
}
cout<<"before while loop" << endl;
char first[25];
char last[25];
int idnum;
float rate, hour;
while(!infile.eof())
{
infile >> first >> last >> idnum >> rate >> hour;
count++;
cout << first <<last << idnum << rate << hour<<endl;
/*
bob[count].fName = first;
bob[count].lName = last;
bob[count].id = idnum;
bob[count].payRate = rate;
bob[count].hours = hour;
cout<< bob[count].fName << bob[count].lName << bob[count].id;
cout << bob[count].payRate<< bob[count].hours <<endl;
*/
}
cout<< "After the infile " <<endl;
cout <<"there are "<<count<< " employees in the file" <<endl;
infile.clear();
infile.seekg( 0L, ios::beg );
ptrToRecord * myArray;
myArray = new ptrToRecord[count];
Sort( myArray[count]->id, count);
infile.close();
return 0;
}
char* getFile()
{
char* file= new char[25];
cout << "Enter file name : ";
cin >>setw(24)>> file;
cout<< "You have enterd " << file << endl;
return file;
}
void Sort( int sortee[], int howMany)
{
int startscan, minIndex, minValue;
for(startscan=0; startscan < (howMany-1); startscan++)
{
minIndex = startscan;
minValue = sortee[startscan];
for(int index= startscan+1; index<howMany; index++)
{
if( sortee[index]< minValue)
{
minValue = sortee[index];
minIndex = index;
}
}
sortee[minIndex] = sortee[startscan];
sortee[startscan] = minValue;
}
}
int search ( int index[], int howMany, int seek)
{
int first, last, middle;
first =0;
last = howMany-1;
bool found = false;
int position= -1;
while(!found && first<=last)
{
middle=(first + last) /2;
if(index[middle] == seek)
{
found = true;
position = middle;
}
else if (index[middle] > seek )
last = middle -1;
else
first = middle + 1;
}
return position;
}
void setId( SimpleRecord &s, int i )
{
if ( i>0 && i<=9999 )
s.id = i;
else
{
cout << " Illegal ID \n NO CHANGE ";
}
}
int getId( SimpleRecord s )
{
return s.id;
}
What should I do to dynamically allocate space from an incoming file, I dont know how to do that so that I can call each element individually and modify them if need be.....How do I do it?!?! I'm so confused, plz help me!