Hi, i'm busy with an assignment and am very new to c++ and to pointers. We are required to use pointers in this assignment as the method frameworks are given. My code compiles but when i run it i get a segmentation fault error. Here is my code:
using namespace std;
Book :: Book()
{
title = new char[MAX_LENGTH];
title[0] = '\0';
}
/** Alternate constructor
@param inTitle The title of the book.
inTitle need not be in title case. */
Book :: Book(char* inTitle)
{
string temp;
int length;
temp=string(inTitle);
if (temp.length() > 150){
int tempNo= temp.length()-150;
temp=temp.substr(0,tempNo);
}
length=temp.size();
for(int i=0;i<length;i++){
title[i]=temp[i];
}
}
Book :: ~Book()
{
delete title;
}
char* Book :: getTitle()
{
convertToTitleCase(title);
return title;
}
/**
@param inTitle The title of the book.
inTitle need not be in title case. */
bool Book :: setTitle(char* inTitle)
{
bool flag = true;
/**
@param[in, out] inTitle After modification this string is in title case
@return true if executed successfully and false if an error occurred
during execution.*/
/bool Book :: convertToTitleCase(char* inTitle)
{