- #1
- 1,757
- 17
Maybe someone can help find what I've done wrong.
I'm using Windows XP, 2.3GHz, 80GB, 256MB, Student Version of MS Visual C++ .NET, 2003 version
I've opened a file up for input, which works fine, but as soon as I try to pull information from the file, it gives exception errors in memory addresses.
If someone can see a blazing error, or knows the fix for this problem, I'd be appreciative.
Relevant code:
This is the file it's trying to read:
I'm using Windows XP, 2.3GHz, 80GB, 256MB, Student Version of MS Visual C++ .NET, 2003 version
I've opened a file up for input, which works fine, but as soon as I try to pull information from the file, it gives exception errors in memory addresses.
If someone can see a blazing error, or knows the fix for this problem, I'd be appreciative.
Relevant code:
Code:
main()
{
// ---------------------------------------------
// Opens file: priorities.dat for
//
ifstream inProcesses("priorities.dat", ios::in);
if (!inProcesses)
{
cerr<<"File could not be opened"<<endl;
exit(1);
}
// Ignore first line from file stream
clearLine( inProcesses );
// --------------------------------------------
// Set up Process pointer array
Process *dataPtr[30]; // Read up to 30 processes
int i=-1;
do
{
dataPtr[++i] = new Process();
}while(inProcesses>>*dataPtr[i]);
.
.
.
}
void clearLine ( ifstream &input ) // Ignores a line from file stream
{
char dump[20];
input>>dump>>dump>>dump>>dump>>dump>>dump>>dump>>dump>>dump;
// This is the line where it quits.
}
// Overloaded input operator from 'Process' object code
istream &operator>>( istream &input, Process &a )
{
input>>a.UserID>>a.ProcessID>>a.PPID>>a.CLS
>>a.Priority>>a.STime>>a.TTY>>a.Time>>a.ProcessName;
// This is the line which it dumps me if I comment out the first one.
return input;
}
This is the file it's trying to read:
Code:
UID PID PPID CLS PRI STIME TTY TIME CMD
johny 27708 27707 TS 48 02:58:05 pts/4 0:00 -tcsh
mikey 27795 27708 TS 48 02:58:52 pts/4 0:00 pine
smitty 27846 27846 TS 40 02:59:12 pts/4 0:00 blah1
ralphy 27915 27916 TS 55 02:59:13 pts/4 0:00 blah2
carly 27925 27926 TS 12 02:59:13 pts/4 0:00 blah3