int StoreDatabase()
{
constint SIZE = 100;
EntryNumber = 0;
ofstream AddToFile;
string sentence;
string FindFile;
string Extention;
string NewFileName;
LetterByLetter Print;
system("cls");
DisplayText = "Which file would you like to add too:";
Print.Text();
cout << endl;
getline(cin, FindFile);
Extention = ".txt";
NewFileName = FindFile + Extention;
FILE *istream;
if ( (istream = fopen ( NewFileName.c_str(), "r" ) ) == NULL )
{
printf ( "File Does Not Exist!\n" );
main();
}
else
{
fclose ( istream );
system("cls");
char sentence[SIZE];
DisplayText = "What would you like to add:";
Print.Text();
cin.getline(sentence, SIZE);
for (int i = 1; i < 100; i++)
sentence[i] = tolower(sentence[i]);
for (int i = 0; i < 1; i++)
sentence[i] = toupper(sentence[i]);
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
AddToFile.open(NewFileName.c_str(),ios::app);
if( AddToFile.is_open())
{
AddToFile.seekp(0,ios_base::end);
AddToFile << "<---------- Entry ---------->" << endl;
AddToFile << sentence<< endl;
AddToFile << "Time Entry Added: " << asctime (timeinfo) << endl;
AddToFile << endl;
}
main();
}
system("PAUSE");
}
When ever i do this i check the text file and the first letter of the sentence the user has given me is gone. do you no how to fix this cause im stumped?
stat() uses the file system metatdata rather than accessing the file itself. There are few operations more expensive than opening a file. And if all you do is open it to ensure that you can is a waste of resources.
I see it all the time. It's also used to check a file size, a seek to the end and seek back to the beginning before a buffer's allocated. It's all caused by these bits of bad sample code lying around.