Segmentation fault

Hello people, I would greatly appreciate someones help on my program. I have to make a word scanner program and I have came to a stop because of this stupid segmentation fault. And i have pin pointed that my program works up to my get_words function which I have below.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void get_words (map <string,int>& words)
{
string orig_word;
string clean;

cout << "get_words";
while (cin >> orig_word)
   {
	cout << endl << "calling clean 2";
	clean_entry(orig_word,clean);

	if (clean.length() > 0)
	  words[clean]++;

	  clean = "";
   }
cout << "get_words";
}


I have those cout statements to show where it stops and its stoping right before where i call a clean_entry function.
like i said really weird so thanks in advance.
Last edited on
closed account (o3hC5Di1)
Hi there,

Welcome to the forums. What does clean_entry() do?

I can see you declare string clean;, but you don't assign a value to it before you pass it on to clean_entry(). Does clean_entry() try to access characters of clean or orig_word which aren't there?

On a sidenote, please wrap your code in [code][/code]-tags, it makes it more readable.

All the best,
NwN
Well clean_entry() iterates through the map and cleans a word from its punctuation mark,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void clean_entry (const string& source, string& target)
{
cout << endl << "clean entry";
 string::const_iterator start_it, end_it;

start_it = find_if(source.begin(), source.end(), alnum);

end_it = find_if(start_it, source.end(), notalnum);

target = source.substr(start_it - source.begin(), end_it - start_it);

for_each(target.begin(), target.end(), low);

}
this is the code for that function. And sorry for the tags will do in the from now on. But i do see what you are telling me and that would seem like the problem any hints on how to solve it??
> I have those cout statements to show where it stops
Get a debugger, execute your program and perform a backtrace where it crashes.
You can look all the variables that you want there.

By the way, ¿do you realize that `cout' is line buffered?
Last edited on
Topic archived. No new replies allowed.