Segmentation fault(core dumped) error

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:

#include "Book.h"
#include <string>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <ctype.h>

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;

string temp=string(inTitle);
if(temp.length()>150){
flag = false;
} else {
title=inTitle;
}
return flag;
}

/**
@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)
{

char current,previous;
string input=string(inTitle);
string line;
string temp;
string lower;
int length;
ifstream myData("minors.txt");

while( myData){
getline(myData,temp);
line=line + temp;
}
length=input.size();
for(int i=0;i<length;i++){
tolower(input[i]);
lower=lower+input[i];
}
length = lower.size();
for(int j=0;j<length-1;j++){
previous=lower[j];
current=lower[j+1];
if(previous == ' '){
if(current==' '){
for(int i=j+1;i<length;i++){
if(i!=length-1){
lower[i]=lower[i+1];
} else {
lower[i]='\0';
length--;
}
}
}
}
}
length=lower.size();
toupper(lower[0]);
for(int i = 0; i<length-1;i++){
previous=lower[i];
if(previous==' '){
toupper(lower[i+1]);
}
}

for(int i=0;i<length;i++){
title[i]=lower[i];
}
return true;
}

Any help would be much appreciated!
Thank you!
http://www.cplusplus.com/forum/general/112111/

- missing proper copy constructor and assignment operator
- matching new[] with delete
- in Book::Book(char*), `title' is uninitialized
Thank you that worked! Appreciate the help!
Topic archived. No new replies allowed.