When I run my switch, choose option 3, my program crashes. Would anyone know how to solve this? I want option 3 to delete node
from my linked list
. I do not know how to do classes. Please don't suggest a fix using classes.
---------------------------------------------------------------------------------------------
my text file looks similar to this
1234 jack hammer 20.00 .45 10
4321 nails 5.00 .20 10
6543 daffy drill 30.00 .50 5
9875 jig blade 317.00 .60 8
---------------------------------------------------------------------------------------------
#include<iostream>
#include<conio.h>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
//******************************************************************************
struct acmetype{
int pid;
char description[25];
float wholesale;
float markup;
int quantity;
acmetype *link;
};
// *******************************
// * Function Prototypes *
// *******************************
ifstream fin; //global variable
void headerfn();
void inputfn(acmetype *&head);
int addfn(acmetype *&head);
int delfn(acmetype *&head);
void printfn(acmetype *head);
//*******************
//* Begin of Main *
//*******************
int main(){
system("color F0");
fin.open("tools.txt");
if(!fin)return 1;
headerfn();
acmetype *head;
inputfn(head);
printfn(head);
cout<<endl<<endl;
cout <<" Press 1 to add node to start and end of list" <<endl;
cout <<" Press 2 to add to the middle of the list" <<endl;
cout <<" Press 3 to delete a product." <<endl<<endl;
cout <<" Please enter in the number from the list above: ";
int choice;
cin>>choice;
switch (choice)
{
case 1:
return addfn(head);
break;
case 2:
//return midfn();
break;
case 3:
return delfn(head);
break;
}
cout<<endl;
cout<<endl<<endl;
system("PAUSE");
}//end of main
//****************************************************************************
int delfn(acmetype *&head)
{
acmetype *pTemp, *nnptr, *currptr; //pTemp temporary node pointer
if( nnptr->link == NULL )
return 0;
else
{
pTemp = nnptr->link->link;
delete nnptr->link;
nnptr->link = pTemp;
if( nnptr->link == NULL )
currptr = nnptr;
}
}//end of del fn
//****************************************************************************