J
Jordan Tiona
Here is my code.
main.cpp:
#include "cddb.h"
CDData* head;
CDData* curData;
int main(){
head = new CDData();
curData = head;
EnterInfo();
Print();
return 0;
}
void EnterInfo(){
CDData* temp;
char* input = new char();
int ipInt;
system("cls");
temp = new CDData();
curData->SetNext(temp);
curData = temp;
cout << "Please enter information about your new CD.\n";
cout << "\nAlbum name: ";
cin.getline(input, 25);
curData->SetAlbumName(input);
cout << "\nArtist name: ";
cin.getline(input, 25);
curData->SetArtistName(input);
cout << "\nYear Released: ";
cin >> ipInt;
curData->SetYear(ipInt);
}
void Print(){
int i = 1;
curData = head;
while(true){
curData = curData->GetNext();
if(curData = NULL)
break;
cout << "CD #" << i << endl;
cout << "Album Name: " << curData->GetAlbumName() << endl;
cout << "Artist Name: " << curData->GetArtistName() << endl;
cout << "Year Released: " << curData->GetYear() << endl;
cout << "-------------------------------------------\n\n";
i++;
}
}
cddb.h:
#include <iostream>
#include <string>
using namespace std;
void EnterInfo();
void Save();
void Load();
void Print();
class CDData {
private:
CDData *next; //For linked list
char* albumName;
char* artistName;
int year;
public:
//Constructor/Destructor
CDData(){ this->SetNext(NULL);}
~CDData(){}
//Accessors
char* GetAlbumName(){return this->albumName;}
char* GetArtistName(){return this->artistName;}
int GetYear(){return year;}
CDData* GetNext(){return next;}
void SetAlbumName(char* newName){albumName = newName;}
void SetArtistName(char* newName){artistName = newName;}
void SetYear(int newYear){year = newYear;}
void SetNext(CDData* newNext){next = newNext;}
};
I'm getting an access violation error during runtime at the print function,
when I'm trying to use the GetXXX accessors.
Unhandled exception at 0x0041fc46 in CDDataBase.exe: 0xC0000005: Access
violation reading location 0x00000004.
What am I doing wrong?
main.cpp:
#include "cddb.h"
CDData* head;
CDData* curData;
int main(){
head = new CDData();
curData = head;
EnterInfo();
Print();
return 0;
}
void EnterInfo(){
CDData* temp;
char* input = new char();
int ipInt;
system("cls");
temp = new CDData();
curData->SetNext(temp);
curData = temp;
cout << "Please enter information about your new CD.\n";
cout << "\nAlbum name: ";
cin.getline(input, 25);
curData->SetAlbumName(input);
cout << "\nArtist name: ";
cin.getline(input, 25);
curData->SetArtistName(input);
cout << "\nYear Released: ";
cin >> ipInt;
curData->SetYear(ipInt);
}
void Print(){
int i = 1;
curData = head;
while(true){
curData = curData->GetNext();
if(curData = NULL)
break;
cout << "CD #" << i << endl;
cout << "Album Name: " << curData->GetAlbumName() << endl;
cout << "Artist Name: " << curData->GetArtistName() << endl;
cout << "Year Released: " << curData->GetYear() << endl;
cout << "-------------------------------------------\n\n";
i++;
}
}
cddb.h:
#include <iostream>
#include <string>
using namespace std;
void EnterInfo();
void Save();
void Load();
void Print();
class CDData {
private:
CDData *next; //For linked list
char* albumName;
char* artistName;
int year;
public:
//Constructor/Destructor
CDData(){ this->SetNext(NULL);}
~CDData(){}
//Accessors
char* GetAlbumName(){return this->albumName;}
char* GetArtistName(){return this->artistName;}
int GetYear(){return year;}
CDData* GetNext(){return next;}
void SetAlbumName(char* newName){albumName = newName;}
void SetArtistName(char* newName){artistName = newName;}
void SetYear(int newYear){year = newYear;}
void SetNext(CDData* newNext){next = newNext;}
};
I'm getting an access violation error during runtime at the print function,
when I'm trying to use the GetXXX accessors.
Unhandled exception at 0x0041fc46 in CDDataBase.exe: 0xC0000005: Access
violation reading location 0x00000004.
What am I doing wrong?