- #1
SMA_01
- 218
- 0
I'm writing a program in C++ that reads integer values from a file. I am trying to run it but it either keeps crashing or running uncontrollably. Here is the function where the problem is:
The area in bold red is the problem, but I can't figure out what exactly the issue is. Any help please?
Thanks.
Code:
void createList(intNode*& intList)
{
intNode* lastInt; //points to last integer in file
lastInt = NULL;
int fileInt; //int read from input file
ifstream intInputFile;
intInputFile.open("intInput.txt");
if (intInputFile.is_open())
{
cout << "intInput.txt open successful" << endl;
}
else
{
cout << "intInput.txt open unsuccessful" << endl;
}
intInputFile >> fileInt;
cout << "check" <<endl;
while(!intInputFile.eof())
{
intNode* anotherInt;
anotherInt = new intNode;
[COLOR="Red"] [B] if(intList==NULL)
{
intList = anotherInt;
lastInt = anotherInt;
lastInt->nextNode = new intNode;
}
else
{
lastInt->nextNode = new intNode;
lastInt = lastInt->nextNode;
lastInt->nextNode = NULL;
}
lastInt->intValue = fileInt;
intInputFile >> fileInt;
cout << "good" <<endl;[/B][/COLOR]
}
cout <<"whats the sitch"<<endl;
intInputFile.close();
cout << "List created from input file" << endl;
}
The area in bold red is the problem, but I can't figure out what exactly the issue is. Any help please?
Thanks.