S
scythemk
Hi,
I am writing a program that, everytime it executes, first loads all
information from a file into a linked list of nodes, using struct to
define it. After manipulating the data and receiving user input, the
program once again outputs the linked list information to the same
file. My problem is that when I'm first trying to get the info from the
file into the linked list I get a bus error. My code is as follows:
struct nodeType
{
string f_name, l_name, course_dep[9], course_num[9];
/*more declarations*/
nodeType *next;
};
int load(nodeType*);
int main()
{
cout<<"test0"; //never prints in program execution, bus error seems
to occur before that
nodeType *start;
load(start);
return 0;
}
int load(nodeType *start)
{
cout<<"test1"; //does not print
ifstream inData;
inData.open("student.dat");
if (inData.fail())
{
cout<<"Could not open file! Please verify that student.dat
exists!";
exit(0);
}
nodeType *current;
current = start;
while (current->next != NULL)
{
/*reading data into the list*/
}
inData.close();
}
If anyone could give me a hint as to what the problem is I would be
very helpful. I have tried using DDD and it throws the seg fault signal
at the load(*start) call but I still don't understand what's wrong.
Thanks a lot.
Ignas
I am writing a program that, everytime it executes, first loads all
information from a file into a linked list of nodes, using struct to
define it. After manipulating the data and receiving user input, the
program once again outputs the linked list information to the same
file. My problem is that when I'm first trying to get the info from the
file into the linked list I get a bus error. My code is as follows:
struct nodeType
{
string f_name, l_name, course_dep[9], course_num[9];
/*more declarations*/
nodeType *next;
};
int load(nodeType*);
int main()
{
cout<<"test0"; //never prints in program execution, bus error seems
to occur before that
nodeType *start;
load(start);
return 0;
}
int load(nodeType *start)
{
cout<<"test1"; //does not print
ifstream inData;
inData.open("student.dat");
if (inData.fail())
{
cout<<"Could not open file! Please verify that student.dat
exists!";
exit(0);
}
nodeType *current;
current = start;
while (current->next != NULL)
{
/*reading data into the list*/
}
inData.close();
}
If anyone could give me a hint as to what the problem is I would be
very helpful. I have tried using DDD and it throws the seg fault signal
at the load(*start) call but I still don't understand what's wrong.
Thanks a lot.
Ignas