This function runs for a bit, then proc_index
variable goes to -1886854513. Is there something wrong with the code?
int parse_words(vector< vector<string> > &temp_word_vec, int num_of_sub_lists)
{
char word[MAX_WORD_LENGTH+1]; // +1 makes room for a newline character
int proc_index = 0; //index of word arr for child process "proc_index"
string word_str;
cerr << "point1\n";
while(fscanf (stdin, "%s", &word) != EOF)
{
cerr << "point2\n";
for(int i = 0; i < MAX_WORD_LENGTH; i++)
{
word[i] = tolower(word[i]);
if(word[i] == '\0')
{
word_str.push_back('\n');
word_str.push_back('\0');
break;
}
if(isalpha(word[i]))
{
word_str.push_back(word[i]);
}
}
cerr << "point3, proc_index = " << proc_index << ", word is " << word_str << "\n";
temp_word_vec[proc_index].push_back(word_str);
++proc_index;
if(proc_index == num_of_sub_lists)
proc_index = 0;
word_str.clear();
}
return 0;
}