Hi,
Basically i have made a small booking program which gets vairious details from the user stores then using a struct and an array, then the user is asked if they would like to save the details to disk, then the program will save the values in a .txt file. All this works fine, the problem is when i want to load the files back into the struct arrays, if the user entered "sometxt sometxt2" only he txt before the space will be loaded back into the program.
here is snipets of the code that reads the values from the txt file into the array/struct.
// read data call
iCount = ReadData(filename, Bookings, iCount);
int ReadData(char fname[], BookingType Arr[], int iNo)
{
ifstream iFile; // internal name of the INPUT file
iFile.open(fname); // open the input file
BookingType temp; // temporary struct
if ( iFile.fail() ) // check for error opening file
{ cout << "Error opening file." << endl;
cout << "Press any key to continue...";
getch();
return iNo; // return the same counter
} // end if open error
// read records
iNo = 0; // start at the begining of the array
while ( !(iFile.eof() ))
{
temp = ReadRecord(iFile);
if ( !(iFile.eof() ))
{
Arr[iNo] = temp;
iNo = iNo + 1;
}
} // all records read
iFile.close(); // finished with file
cout << iNo << " Records read from file " << fname << endl;
return iNo; // return the new counter
}
BookingType ReadRecord(ifstream& file)
{
BookingType temp; // temporary struct
file >> temp.iAdvanceDays;
file >> temp.sDepAirport;
file >> temp.sArrivalAirport;
file >> temp.sName;
file >> temp.sAddress;
// return the temporary struct
return temp ;
} // end ReadRecord()