0
LinkedList::LinkedList(const value_type& input)
{
value_type delim = " ";

int start = 0;

size_t pos = 0;

value_type nWord;

value_type tString = input;

while ((pos = tString.find(delim)) != value_type::npos) {
    nWord = tString.substr(0, pos);
    std::cout << nWord << std::endl;
    tString.erase(0, pos + 1);
}

std::cout << tString << std::endl;
}

LinkedList firstSen("i am testing A linked list");

LinkedList secSen("again i am testing");

i am trying to print out a sentence into words before i add them to nodes in my linked list (to test if its working). when i create the linked lists firstsen and secsen in my main function i am getting the output of all the words separated by new lines (which is what i want) but at the end it says "Segmentation fault (core dumped)".

I think this means im reading memory i dont have access to but i cant figure out what is causing that.

  • 1
    If you're going to make a copy of the input to modify, you might as well pass it by value. – eesiraed Mar 26 '18 at 03:50
  • Have you tried using a debugger? – eesiraed Mar 26 '18 at 03:51
  • Possible duplicate of [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – Raedwald Mar 26 '18 at 06:42

0 Answers0