Problem with my searching function

Hey guys, I have written a function that is supposed to find all the occurrences of a given word in a text file. In this case the word "the" is sent, and all the occurrences of "the", "The" and "THE" has to be counted in the text file, but for some reason I'm getting a segmentation fault and I cant figure out why. Any help would be appreciated, here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int WordCount :: countWords(string wrd)
{
	int counter=0;
	string temp = "";
	while (getline(*file,temp))
	{  
	  for (int i = 0; i < temp.length()-3;i++)
	  {
		if ((temp[i] + temp[i+1] + temp[i+2]) == (wrd[0] + wrd[1] + wrd[2]))
		{
		  counter++;
		}
		if ((temp[i] + temp[i+1] + temp[i+2]) == toupper(wrd[0] + wrd[1] + wrd[2]))
		{
		counter++; 
		}
	  }
	}
	
	return counter;	
}
http://www.cplusplus.com/forum/general/112111/

> while (getline(*file,temp))
¿why is `file' a pointer?

> if ((temp[i] + temp[i+1] + temp[i+2]) == (wrd[0] + wrd[1] + wrd[2]))
In this context, `+' means addition, not concatenation.
Topic archived. No new replies allowed.