| | |
General Protection Exception Error Please Help!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 2
Reputation:
Solved Threads: 0
Hello,
This is my first post. Anyway.. I am having trouble with my c++ program. My assignment is to read from a file a 2-Dimensional array. However, when attempting to do so with my code, which i'm guessing is faulty, I keep getting this error while using Borland Turbo C++ 4.5:
General Protection Exception
0x9CF7:0x4D58
Program2(1) 0x9CF:0x4D58 Processor Fault
Here is my code and I have also attached my files:
If anyone can help it would be greatly appreciated! THANKS!
This is my first post. Anyway.. I am having trouble with my c++ program. My assignment is to read from a file a 2-Dimensional array. However, when attempting to do so with my code, which i'm guessing is faulty, I keep getting this error while using Borland Turbo C++ 4.5:
General Protection Exception
0x9CF7:0x4D58
Program2(1) 0x9CF:0x4D58 Processor Fault
Here is my code and I have also attached my files:
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <iomanip.h> #include <math.h> #include <stdlib.h> #include <fstream.h> #include <ctype.h> int grade[15][6]; /********************************************************/ void fileopen() { char ch; fstream Infile; Infile.open("program2.txt", ios::in); if (!Infile) { cout<<"File not found!"; } int i=0, h=0; while (ch = Infile.peek() != EOF) { Infile >> grade[i][h]; i++; h++; } Infile.close(); } /********************************************************/ int displaygrades() { fstream Infile; for (int i=0; i < 15; i = i + 1) { for(int h=0; h < 6; h = h + 1){ Infile << grade[i][h] <<"\n"; } } } /********************************************************/ int main() { fileopen(); displaygrades(); return 0; }
If anyone can help it would be greatly appreciated! THANKS!
What do you think is the loop condition in the following line? [edit]Actually that whole loop is wrong.
C++ Syntax (Toggle Plain Text)
while (ch = Infile.peek() != EOF)
you should anyway use ifstream instead of fstream for reading...
Omitting all errorchecking, the following will read and echo lines from a textfile:
Omitting all errorchecking, the following will read and echo lines from a textfile:
C++ Syntax (Toggle Plain Text)
#include <fstream> #include <string> #include <iostream> #include <iomanip> int main() { ifstream fs; fs.open("test.txt"); string s; while (fs >> s) cout << s << endl; fs.close(); }
•
•
Join Date: Dec 2004
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by jwenting
you should anyway use ifstream instead of fstream for reading...
Omitting all errorchecking, the following will read and echo lines from a textfile:
C++ Syntax (Toggle Plain Text)
#include <fstream> #include <string> #include <iostream> #include <iomanip> int main() { ifstream fs; fs.open("test.txt"); string s; while (fs >> s) cout << s << endl; fs.close(); }
I assume you have 1 row of the array in each line of your input file, and the records (so columns in that row) are separated in some way that you can detect.
What you do is you use that criterion to split up the string you read (it reads a line at a time in my code) and fill the columns of your array with the resulting data.
So in pseudo code:
What you do is you use that criterion to split up the string you read (it reads a line at a time in my code) and fill the columns of your array with the resulting data.
So in pseudo code:
C++ Syntax (Toggle Plain Text)
while no readerror on read line split line set columns increase counter wend
![]() |
Similar Threads
- general protection error (C++)
- Help!!!!!! General Protection Exception (C++)
- IEXPLORE caused a general protection fault (Web Browsers)
- I keep getting an error message on my computer called General Protection Exception... (C++)
Other Threads in the C++ Forum
- Previous Thread: Need help with this conversion program
- Next Thread: C++ Data Types
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






