Hi!
I'm using windows 98 and Turbo C++.
Is there a way to keep from getting the following error message:
------------------------------------
Unhandled Exception
!
General Protection Exception
0x12CF:0x437B
DATATEST(1) 0x12CF:0x437B Processor
Fault
[OK]
------------------------------------
Processor Fault? I know I only have 24MG of RAM
which by today's standards is Neolithic in computer years.
It couldn't be RAM could it?
Also, I was under the impression that fflush(stdin);
was supposed to empty the data and make room for correct data... I'm wrong, aren't I?
heres a snippet of code and pseudo-code for this program (its too long to post the whole thing so I put this much which compile fine for me)
Now if the use 'misbehaves' and types in like 120 characters,
I get that error message. Please enter too many characters to see what I mean:
// filename: 'datatest.cpp'
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
main() {
char filename[40];
char firstname[30];
FILE *handle;
// 1. ask for path and filename:
cout << "Enter The Full MS-DOS Path Of The File You Need To Open\n";
gets(filename);
clrscr();
// 2 & 3. open file and error check to see if it opens:
if ((handle = fopen(filename, "a")) == NULL)
{
perror("filename (fopen)");
exit(EXIT_FAILURE); // same as exit(1);
}
else
{
cout << "File Opened Successfully.\n";
cout << "Press Any Key\n";
getch();
clrscr();
}
// 4. ask for name
fflush(stdin);
cout << "First Name:\n";
gets(firstname);
while (strlen(firstname) > 30)
{
fflush(stdin);
cout << "\n\nRe-Enter First Name (less than 30 char):\n";
gets(firstname);
}
// 5. append information to a file:
fputs(firstname, handle);
fputs("\n", handle);
// 6. close file & exit:
fclose(handle);
exit(0);
return 0;
}
Thankyou!