Think I have a getline problem....
My output is coming out very odd, essetially my program does the following, opens two files and inputs the strings of each file for the following variables:
function function2
partnerName partnerName2
partnerId partnerId2
equipType equipType2
equipNumber equipNumber2
counter dateTime2
dateTime
I use a fin.ignore() and fin.getline (dateTime, 30) since the date will have spaces.
This works fine when inputing from the first file, but does not input the information correctly from the second file. I checked the steps in which each file is written to and created and they are identical.
This is my code, you'll notice alot of uncessary couts in there,I use to try and find where I am going wrong. I think its a getline problem but I've used this in a similar fashion before????
# include <fstream.h>
# include <string.h>
# include <stdlib.h>
int main ()
{
//list variables for input and output
char function [9];
char partnerName [30];
char partnerId [11];
char equipType [15];
char equipNumber [7];
int counter;
char function2 [9];
char partnerName2 [30];
char partnerId2 [11];
char equipType2 [15];
char equipNumber2 [7];
int counter2;
char dateTime [30];
char dateTime2 [30];
int stopBit = 0;
int stopBit2;
//open files for input of information
ifstream fin;
fin.open ("G:\\HEHP\\HVMDATALOGOUT.txt", ios::in | ios::nocreate | ios::eofbit);
if (fin.fail ())
{
return EXIT_FAILURE;
}
//do
while (!fin.eof () && (stopBit <1))
{
//input from Check Out log file
fin >>ws;
fin >> function;
fin >> partnerName;
fin >> partnerId;
fin >> equipType;
fin >> equipNumber;
fin >> counter;
fin.ignore ();
fin.getline (dateTime, 30);
cout<< function<<endl;
cout<< partnerName<<endl;
cout<< partnerId<<endl;
cout<< equipType<<endl;
cout<< equipNumber<<endl;
cout<< counter<<endl;
cout<< dateTime<<endl;
cout <<"**************************************"<<endl ;
ifstream fin2;
fin2.open ("G:\\HEHP\\HVMDATALOGIN.txt", ios::in | ios::nocreate | ios::eofbit);
if (fin2.fail ())
{
return EXIT_FAILURE;
}
stopBit2 = 0;
while ((strcmp(equipNumber, equipNumber2)!=0) && (!fin2.eof()) && (stopBit2<1))
{
//input from Check In log file
fin2 >> ws;
fin2 >> function2;
fin2 >> partnerName2;
fin2 >> partnerId2;
fin2 >> equipType2;
fin2 >> equipNumber2;
fin2.ignore ();
fin2.getline (dateTime2, 30);
fin2 >>ws;
cout <<function2<<endl;
cout <<partnerName2<<endl;
cout <<partnerId2<<endl;
cout <<equipType2<<endl;
cout <<equipNumber2<<endl;
cout <<dateTime2<<endl;
cout <<"##############################################" <<endl;
if ((strcmp(equipNumber, equipNumber2)!=0))
{
if (fin2.eof())
{
stopBit2 =1;
ofstream fout;
fout.open ("G:\\HEHP\\HVMDATALOGOUT2.txt", ios::out | ios::app);
if (fout.fail ())
{
cout <<"Unable to open file HVMDATALOGOUT2.txt"<<endl;
return EXIT_FAILURE;
}
cout<<"writing to the data2 file"<<endl;
cout <<function<<endl;
cout <<partnerName<<endl;
cout <<partnerId<<endl;
cout <<equipType<<endl;
cout <<equipNumber<<endl;
cout <<counter<<endl;
cout <<dateTime<<endl;
fout <<function<<" "<<partnerName<<" "<<partnerId<<" "
<<equipType<<" "<<equipNumber<<" "<<counter<<"\n"
<<dateTime<<endl;
fout.close();
fin2.close();
}
}
else if ((strcmp(equipNumber, equipNumber2)==0))
{
cout <<"Match found !!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
fin2.close ();
}
};
if (fin.eof())
{
stopBit = 1;
fin.close();
return EXIT_SUCCESS;
}
};
fin.close();
}
sorry for the lacking code tags
I see your point, I wont forget this in the future.... will try to insert \n in at the end of the checkin records maybe this will help,
will try to mull over the fin fout declarations outside the loops, not sure on that, but at this point I willing to try gargling peanutbutter and standing on my head, need step away and get a fresh perspective.....