Ok, after much help from everyone at this site, I've run upon my newest problem using an array of structs.
I successfully get the data loaded into the array, map it correctly and can call the information from the struct loaded in the subscript of the array.
However, when I try to use the data I store in a very robust array of struct, I appear to just get memory addresses, not the values. I've tried about 30 combinations of calls to get the results, which I know are there, because as a process the data and its being loaded into the structs I see it on screen. Am I not getting to the proper location of the array or am I just calling a memory address not the value. I've attached my code, thanks as always for looking.
Code:
#include <fstream.h>
#include "string.h"
//define struct
struct partnerInfo
{
char partnerId [11];
int casecount;
int wavenumber;
int starttime;
int endtime;
int station;
char date [11];
};
int main ()
{
//list variables for input record type
char recType;
char date [11];
float hours;
float minutes;
float seconds;
char partnerName [30];
char partnerId [11];
int stationId;
char eventType [30];
int waveNumber;
char tableName [11];
char tableId [11];
int count = 0;
int count2 =0;
int index;
int totalTime = 0;
int MasterCount = 0;
int mcCount3 = 0;
//open file for input and grab first record
/* ifstream fin;
fin.open("C:\\data\\MoLic2.txt");
if (fin.fail())
{
cout <<"file open failed!"<<endl;
} */
ofstream fout;
fout.open("C:\\palletperf.txt", ios::app);
if (fout.fail())
{
cout <<"FAILED TO OPEN OUTPUT FILE"<<endl;
}
else
{
/* do
{
fin >> recType;
fin >> date;
fin >> hours;
fin >> minutes;
fin >> seconds;
fin >> partnerName;
fin >> partnerId;
fin >> stationId;
fin.ignore();
fin.getline(eventType, 30);
//declare array of strings for station to partnerId reference
char stations [20] [11];
//determine recType and populate array if necessary
if (recType == 'P')
{
strcpy( stations[stationId], partnerId ); //set element equal to partnerId
cout <<stations[stationId]<<endl; //display the element just set
}
else if (recType == 'L')
{
fout <<stations [stationId]<<" "<<partnerId<<" "<<stationId<<" "<<hours<<" "
<<minutes<<" "<<seconds<<" "<<date<<" "<<recType<<" "<<eventType<<endl;
cout <<"record written"<<endl;
}
}while (!fin.eof());
fin.close();
fout.close(); */
//open partnerlist.txt and palletperf.txt compare strings to match name with records
ifstream fin1;
fin1.open("C:\\palletperf.txt", ios::eofbit);
if (fin1.fail())
{
cout <<"failed to open palletperf.txt";
}
ifstream fin2;
fin2.open("C:\\partnerlist.txt");
if (fin2.fail())
{
cout <<"failed to open partnerlist.txt";
}
ofstream fout2;
fout2.open("C:\\palletresults.txt", ios::app);
//input partners ids into array table for binary search
char partnerTable [300] [11];
do
{
fin2>>tableName;
fin2>>partnerTable[count];
// cout <<partnerTable[count]<<endl;
count++;
}while (!fin2.eof());
//load struct values
partnerInfo partnerList [300] [21] ;
do
{
fin1>>partnerId;
fin1>>waveNumber;
fin1>>stationId;
fin1>>hours;
fin1>>minutes;
fin1>>seconds;
fin1>>date;
fin1>>recType;
fin1>>eventType;
//run linear search on partnerTable array to find index point for struct array
while (count2 <100)
{
if ((strcmp(partnerTable[count2], partnerId)==0))
{
index = count2;
}
count2++;
};
//calculate total seconds
totalTime = (hours*3600)+(minutes*60)+seconds;
cout <<MasterCount<<endl;
if (MasterCount<1)
{
int mcCount1 = 0;
int mcCount2 = 0;
do
{
do
{
// cout << "setting counts to zero"<<endl;
partnerList[mcCount1] [mcCount2].casecount =0;
partnerList[mcCount1] [mcCount2].starttime =0;
partnerList[mcCount1] [mcCount2].endtime =0;
mcCount2++;
}while (mcCount2<21);
mcCount2 = 0;
mcCount1++;
}while ((mcCount1 <300));
}
//determine partner to add to list array of struct for wavelist
strcpy(partnerList[count2] [waveNumber].partnerId, partnerId);
partnerList[count2] [waveNumber].station = stationId;
partnerList[count2] [waveNumber].wavenumber = waveNumber;
strcpy(partnerList[count2] [waveNumber].date, date);
partnerList[count2] [waveNumber].casecount++;
//determine if this is first record for wave
if (partnerList[count2] [waveNumber].starttime==0)
{
partnerList[count2] [waveNumber].starttime = totalTime;
}
partnerList[count2] [waveNumber].endtime = totalTime;
MasterCount++;
//test only display results
/* cout<<partnerList[count2] [waveNumber].partnerId<<" "
<<partnerList[count2] [waveNumber].wavenumber<<" "
<<partnerList[count2] [waveNumber].station<<" "
<<partnerList[count2] [waveNumber].casecount<<" "
<<partnerList[count2] [waveNumber].starttime<<" "
<<partnerList[count2] [waveNumber].endtime<<" "
<<partnerList[count2] [waveNumber].date<<endl; */
}while (!fin1.eof());
//close all output and input files
// fin.close();
fin1.close();
fin2.close();
//filter through arrays of data and calculate percentages
do
{
//open output file for end results to load listbox
ofstream fout3;
fout3.open("C:\\palletperfList.txt", ios::app);
int mcCount4 = 0;
int totalSec = 0;
int totalHrs = 0;
int totalCss = 0;
int casperHr = 0;
int percent = 0;
do
{
//input array values and then make calculations
totalSec = partnerList[mcCount3] [mcCount4].endtime - partnerList[mcCount3] [mcCount4].starttime;
totalHrs = totalSec/3600;
totalCss = partnerList[mcCount3] [mcCount4].casecount;
// casperHr = totalCss/ totalHrs;
percent = (casperHr / 300) * 100;
cout <<partnerList[mcCount3] [mcCount4].partnerId<<" "
<<partnerList[mcCount3] [mcCount4].wavenumber<<" "
<<partnerList[mcCount3] [mcCount4].station<<" "
<<casperHr<<" "<<percent<<" "
<<partnerList[mcCount3] [mcCount4].date<<endl;
mcCount4++;
}while (mcCount4<21);
mcCount4 = 0;
mcCount3++;
}while ((mcCount3 <300));
}
}