I am trying to write a code that reads data from a file, after reading the data it should look for duplicate and write only non duplicate values to a new file. however, when I run the program I get a segmentation error inside GetNext(). I've gone through the code several times I can't seem to find the invalid pointer inside GetNext() function. can any body help! see the code bellow.
//===========================================================================
// hybrid.h -- Specification file for hybrid class
// Time-stamp: <2010-10-25 19:24:46 Dnambembe>
// To compile:
//
// Copyright (c) 2010 by Domingos Nambembe. All rights reserved.
//===========================================================================
#include<fstream>
#define OUTDATA "licence.txt" // reading from file
#define fn "Noduplicate.text" //sorted file
struct NodeType; //Forward declaretion, complete declaretion is hiden
struct Record;
typedef Record ComponentType; // in implementation file
class HybridList
{
public:
void GetNext(); // extracts record from a file Licensea
void ReStart(); // calls getnext to get data
void SaveDB(Record* K); //create file with no duplicate
bool IsEmpty() const;
//condition:
// function value == true. if list is empty
// == false, otherwise
void Insert();
// precondition item is not in the list
//postcondition: item inserted && list is in ascending order
void Delete( ComponentType item);
// precondition: item is somewhere in list
//postcondition: item deleted && list in ascending order
HybridList();
// default constractor
// empty list is created
//HybridList(const SortedList& otherlist);
// copy-constractor, list is created as duplicate
~HybridList();
// destructor
// list is destroyed
private:
NodeType* head;
//Record Data;
};
//===========================================================================
// testhybrid.cpp --a test driver for the hybridlist class
// Time-stamp: <2010-10-29 18:52:46 Dnambembe>
// To compile:
// g++ testhybrid.cpp hybrid.o
// Copyright (c) 2010 by Domingos Nambembe. All rights reserved.
//===========================================================================
#include"hybrid.h"
#include<iostream>
usingnamespace std;
int main()
{
HybridList object;
for(int i = 0; i < 3; i++)
{
// object.ReStart();
object.GetNext();
object.Insert();
cout<< " Licensea file has been sorted and written to new file" <<endl;
}
}
Tho this might not help regarding your question, i suggest try to use a debugger, i found DDD debugger to be very good, easy to use and good to find problems, especially when working with pointers.