Hi
I have a program i was writing to solidify my knowledge of files and how to handle them. I seem to have hit a snag though. What the program does is create files based on a user inputted date and allows them to add content to the files (kind of like a schedule book). The feature I am having trouble with is the part of the program that displays the contents of the file. It starts at a user inputted date and searches for files within a given range of that date. The problem is that the program will only display a file's contents if it is on the date entered by the user.
e.g: User enters in 1-5-08 for the date. He knows he has files saved for 1-5, 1-6, and 1-8-08 but only the one on 1-5-08 is displayed.
I tracked the file name through the functions it goes through and it stays correct all the while but it still won't open when I need it.
I have posted all the relevant code for you to look at.
This is the function that creates the file name from the date:
void fileName()
{
ifstream fin;
ofstream fout;
fout.open("fileCreate");
fout << month;
fout << day;
fout << year;
fout.close();
fin.open("fileCreate");
fin >> file;
fin.close();
DeleteFile("fileCreate");
return;
}
This is the function that opens and reads the file:
void viewEntries()
{
ifstream fin;
ofstream fout;
cout << "Date to start searching:" << endl;
cout << "Year: ";
cin >> year;
cout << "Month: ";
cin >> month;
cout << "Day: ";
cin >> day;
cout << endl;
dayCount=daysInAdvance;
for (dayCount; dayCount>0; dayCount--)
{
dayOverlap();
fileName();
fin.open(file);
if (!fin)
{
cout << "\nNo entry on: " << month;
cout << "-" << day;
cout << "-" << year;
}
while (fin.get(ch))
cout << ch;
fin.close();
else
{
cout << "\nEntry found on: " << month;
cout << "-" << day;
cout << "-" << year << endl << endl;
while (fin.get(ch))
cout << ch;
}
fin.close();
day++;
}
cout << endl;
menu();
}