I am writing a program to help me out at work. I run the dispatch board at a local trucking company and the program is designed to help me keep track of pick up requests that are called in by customers. I am getting an error that I cannot track down. When I run the program (at least, what I have so far) Windows tells me that the program encountered a problem and needs to shut it down. After quite a bit of debugging I found this window that poped up "An access violation (Segmentation Fault) raised in your program". This is a fairly large program with multiple modules so I will just post the relevant parts.
I have a struct to record pick up requests
Code:
struct PickUp_Info
{
string name; // customer name
string address1; // address
string address2; // address
string city; // city
string state; // state
string ozip; // zip
string route; // route number
string drivername; // assigned driver name
int drivernumber; // number
int punum; // pick up number
int pcs[10]; // (up to 10 bills) pieces
int weight[10]; // weight
string dzip[10]; // destination zip code
string pro[10]; // tracking number
string enter_time; // time pick up was entered
string ready_time; // time pick up is ready
string close_time; // time customer closes
string assign_time; // time assigned to driver
string confirm_time;// time driver made pick up
string contact; // company contact name
string phone; // company contact number
string comments; // comments on pickup, special directions
};
and this class to manage all of the pick up requests
Code:
class PickUp_Manager
{
public :
PickUp_Manager() { };
~PickUp_Manager() { };
void Print_Report();
void Clear_Plan();
int Get_Number();
void Get(int x);
vector<PickUp_Info>::iterator Check_PickUp(int x);
void Clear_Fields();
void Save(bool save);
vector<int> reference_list;
PickUp_Info pickup;
int total_pcs, total_weight, total_calls;
int line_num, confirm_count, pu_num;
private :
void PickUp_Manager::Sort_PickUp();
vector<PickUp_Info> pickup_list;
};
The program displays a screen with blanks for all of the information for the pick up request and the user can tab through the blanks and enter all of the information. Then ReadConsoleOutputCharacter() is used to record all the information into the struct using this function
Code:
string ReadCursor(int x, int y, int z)
{
char tempchar[z];
string tempstring;
COORD Position;
DWORD NumRead;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
Position.X = x;
Position.Y = y;
ReadConsoleOutputCharacter(hOut, tempchar, z, Position, &NumRead);
tempstring.assign(tempchar, 0, z);
return tempstring;
}
And here is the part of the program that I am having problems with
Code:
void Save_PickUp(PickUp_Manager& PickUp, bool save)
{
string temp;
PickUp.pickup.name = ReadCursor(26, 3, 25);
PickUp.pickup.address1 = ReadCursor(26, 5, 25);
PickUp.pickup.address2 = ReadCursor(26, 7, 25);
PickUp.pickup.city = ReadCursor(26, 9, 15);
PickUp.pickup.state = ReadCursor(26, 11, 2);
PickUp.pickup.ozip = ReadCursor(26, 13, 5);
PickUp.pickup.route = ReadCursor(26, 15, 2);
PickUp.pickup.contact = ReadCursor(26, 17, 25);
PickUp.pickup.phone = ReadCursor(26, 19, 12);
for (int i = 0; i <= 9; i++)
{
temp = ReadCursor( ( (i * 8) + 8), 23, 3);
if (temp != " ")
PickUp.pickup.pcs[i] = atoi(temp.c_str() );
else PickUp.pickup.pcs[i] = 0;
temp = ReadCursor( ( (i * 8) + 8), 25, 5);
if (temp != " ")
PickUp.pickup.weight[i] = atoi(temp.c_str() );
else PickUp.pickup.weight[i] = 0;
PickUp.pickup.dzip[i] = ReadCursor( ( (i * 8) + 8), 27, 5);
}
PickUp.pickup.comments = ReadCursor(10, 29, 80);
PickUp.pickup.ready_time = ReadCursor(13, 31, 4);
PickUp.pickup.close_time = ReadCursor(41, 31, 4);
PickUp.pickup.enter_time = ReadCursor(70, 31, 4);
PickUp.Save(save);
return;
}
After the for loop calls the ReadCursor function for the third time in the first cycle the error comes up as soon as the function returns to the caller. I thought that it might be trying to access bad memory but I don't see it. I am at a loss here. I hope I explained this well enough for everyone to understand, any help will be greatly appreciated.