Here, i am editing my question.
while (iter <= k && getline(input, line))
{
searchWord.clear();
int len = line.length();
if (len == 0) // getline function was not getting the third line. It was empty so. at 2-3 lines below. It was giving run time error because it was trying to access a vector's element fileed with empty string(line)
{
cout << count << " Words are Found:" << total_words << endl;
return 0;
}
for (int i = 0; i < len; i++)
{
ch1 = line.at(i);
searchWord.push_back(ch1);
}
for (int col = 1; col <= n; col++)
{
for (int row = 1; row <= n; row++)
{
if (mat[col][row] == searchWord[0]) // aranıalcak kelımenın boyutuna erisılene kadar harf harf matrix in ilk harfi ile aranan kelımenın ılk harfı sonra 2. harfı uyuyot mu dıye bakılacak bu loop un ıcıne spiral gitme algoritması yazılacak.
{
if (found(mat, searchWord, row, col)) // spiral arama loop u
{
count++;
for (int i = 0; i < searchWord.size(); i++) // if word is found add it to total words and afterwards leave a space.
{
total_words += searchWord[i];
}
total_words += " ";
}
}
}
}
row = 1;
iter++;
}
this code does not work for 3rd time .For example lets say this is our file contains these words seperated with only enter
EXAM QUIZ NOTFOUND
it gets exam and quiz perfectly and does eerything right. But it does not gets "NOTFOUND" in line at 3rd iteration of loop. So it does not enter the for loop at beginning and it crashes when it tries to reach outside of the searchWord vector.
What could be done ?