Strings from file

Hey guys I've been all sorts of methods on trying to find particular strings from a file that has thousands of strings. Im searching for palindromes, I have a code that actual determines if a word is a palindrome but the process of finding it im stuck on, I assume its a loop or a getline. Any help, tips or hints would highly be appreciated. Heres my function for the palindrome.

// returns true if word is a palindrome, false if not.
bool isPalindrome(const char word[])
bool is_palindrome = true;
// assume it's a palindrome until we see a mis-match

int len = strlen(word);
int index_of_last = len - 1;

/* Only first half of array needs to be checked
(since we're comparing it to the second half).
Here we WANT integer division -> integer result:
works for odd and even number of characters.
If we find a mis-match, this is not a palindrome and we should stop looping.
for (int i=0; i<len/2 && is_palindrome; i++)
if (word[i] != word[index_of_last - i])
is_palindrome = false; // not a palindrome

return is_palindrome;
I think you could strstr() it
i looked up strstr() I understand the logic but cant see how to incorporate that with the accessed file to find these palindromes? Thanks for input anymore would be appreciated.
Is your .txt file in this sort?





This will only work for first method.

Use #include <fstream> to use .txt file to program input. Then put each word into a slot in an array. Use strstr() on both arrays.
Topic archived. No new replies allowed.