Whenever I try to do and Application function I am returned with "Segmentation Fault" Core dumped, I don't quite know where the error is coming from. So any help on where it is or how to find it would be appreciated
LinkedList.cpp
#include "linkedList.h"
#include "myDate.h"
#include <iostream>
usingnamespace std;
#include <fstream>
//FillList
//Description: opens a file and fills the list from the file
//Parameters: indexList
//Return: none
void FillList(linkedList<myDate> &list);
//DisplayList
//Description: displays the list to the monitor
//Parameters: indexList
//Return: none
void DisplayList(linkedList<myDate> list);
//AddToList
//Description: adds to the list by ordered insert
//Parameters: indexList,num
//Return: none
void AddToList(linkedList<myDate> &list);
//GetTodaysAppointments
//Description: Asks the user for today's date, and looks for a matching date from the list
//Parameters: indexList,num
//Return: none
void GetTodaysAppointments(linkedList<myDate> list);
//ChangeAppointment
//Description: Lets the user choose an appointment to change, and changes as such
//Parameters: indexList
//Return: None
void ChangeAppointment(linkedList<myDate> &list);
//Menu
int menu();
int main()
{
int choice;
int num;
linkedList<myDate> L;
while ((choice = menu()) != 6)
{
switch (choice)
{
case 1: FillList(L); break;
case 2: AddToList(L); break;
case 3: GetTodaysAppointments(L); break;
case 4: ChangeAppointment(L); break;
case 5: DisplayList(L); break;
}
}
return 0;
}
//menu
int menu()
{
int ch;
cout << endl;
cout << "1. Fill from file" << endl;
cout << "2. Add to the list" << endl;
cout << "3. Get Todays Appointments" << endl;
cout << "4. Change an appointment" << endl;
cout << "5. Display list" << endl;
cout << "6. Quit"<<endl;
cout << "Choice: ";
cin >> ch;
return ch;
}
//FillList
//Description: opens a file and fills the list from the file
//Parameters: indexList
//Return: none
void FillList(linkedList<myDate> &list)
{
myDate aDate;
myTime aTime;
ifstream f;
bool result =true;
string fname;
cout << "File: ";
cin >> fname;
f.open(fname.c_str());
if (f.fail())
{
cout << "Failed to open" << endl;
return;
}
list.begin();
f >> aDate;
while (result && !f.eof())
{
f>>aTime;
aDate.setTime(aTime);
list.orderedInsert(aDate);
f>>aDate;
}
f.close();
}
Probably line 93. You tried to make a comparison to current->data, except the linked list is empty. In other words, current is a null pointer, and you just tried to ask what a null pointer points to. Hence, segfault. Consider throwing in an empty check to your orderedInsert function to avoid that problem easily.