|
-
Mar 16th, 2002, 12:01 PM
#1
Thread Starter
New Member
Need some help, simple newbee program crashes!!
I really need help, critical error occures when tryong to run the
code, and I have no clue what it could be.
Im attaching the .cpp file to this message, so you can better
see what it is.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
using namespace std;
// *********Function Declarations Start***********
void loadFile();
void saveFile();
void removeFile();
void fileMenu();
//*********Function Declarations End***********
// Function for loading a file START
void loadFile()
{
const int s_length = 100;
const int b_size = 10000;
char fileName[100];
char buffer[b_size];
cout << "Print a name for the file to load" << endl;
cout << "Filename:" << flush;
cin.getline(fileName,(s_length-1),'\n');
ifstream input(fileName,ios::in);
if (!input.is_open())
{ cerr << "Unable to open the file " << fileName << endl; }
while (!input.eof())
{
input.getline(buffer,(b_size - 1));
cout << buffer << endl;
}
input.close();
}
// Function for loading a file END
// Function for saving a file START
void saveFile()
{
const int s_length = 100;
char fileName[s_length];
cout << "Print a name for the file to save" << endl;
cout << "Filename:" << flush;
cin.getline(fileName,(s_length - 1),'\n');cin.get();
ofstream output(fileName,ios: ut);
if (output.is_open())
{
output << "---------------------------------------------------" << endl;
output << "This file was created by: [ZiX] STRIDER, using VC++" << endl;
output << "---------------------------------------------------" << endl;
output << endl;
cout << "This text is automatically generated by the program" << endl << "the user will type this text to the file, when I get the" << endl << "program to work properly." << endl;
cout << "The file: " << fileName << " was successfully created" << endl << endl;
}
output.close();
}
// Function for saving a file END
// Function for removing a file START
void removeFile()
{
const int s_length = 100;
char fileName[100];
cout << "Print a name for the file to remove" << endl;
cout << "Filename:" << flush;
cin.getline(fileName,(s_length-1),'\n');
if (remove(fileName) == -1)
{ cerr << "Unable to remove the file " << fileName << endl; }
else
{
cout << "The file: " << fileName << " was successfully removed" << endl << endl; }
}
// Function for removing a file END
// fileMenu Start
void fileMenu()
{
char menuChoice;
while(menuChoice != '4')
{
cout << "* * * * * * * * * * * * * * * * * * * * * * * * *" << endl;
cout << "This is a File Handeling Test, for recall purpose" << endl;
cout << "* * * * * * * * * * * * * * * * * * * * * * * * *" << endl << endl;
cout << "What do you want to do?" << endl;
cout << "1.Create a file" << endl;
cout << "2.Load a file" << endl;
cout << "3.Remove a file" << endl;
cout << "4.Exit program" << endl;
cin >> menuChoice;
switch (menuChoice)
{
case '1':
system("cls");
saveFile();
break;
case '2':
system("cls");
loadFile();
break;
case '3':
system("cls");
removeFile();
break;
case '4':
system("cls");
cout << "Good-Bye!" << endl;
break;
default:
break;
}
}
}
// fileMenu END
int main()
{
fileMenu();
return 0;
}
You can´t hit what you cant see
-
Mar 16th, 2002, 02:55 PM
#2
Monday Morning Lunatic
Have you tried running it through the debugger?
Make sure you're using the Win32 - Debug build, and then hit F5 to start it. When it crashes, you can then break into the debugger and see what line it's on
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|