Help with an EOF loop

So this program takes a string. asks for a charaacter to look for. And then if that character is in the string it will reverse the string. It needs to be in an end of file loop. Also for whatever reason it always reverses, instead of just when it finds character.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<string>
using namespace std;

void findCharInString (std::string input, char charToFind);
void Reverse(string &word);
int main()
{
string word;
char character;

cout<<"Please enter a string: ";
cin>>word;
cout<<"Please enter a character: ";
cin>>character;

findCharInString (word, character);

return 0;
}

void findCharInString (string input, char charToFind)
{
bool correct = true;
  for (int i=0; i<input.length(); ++i)
  {
    if (input[i] == charToFind)
    {
       correct = true;
     }
   }
   if (correct==true)
      {
      Reverse(input);
      cout<<input;
      }
}

void Reverse(string &word)
{
        int i;
        char temp;
        
        for (i=0; i<word.length()/2; i++)
        {
        	temp = word[i];
        	word[i] = word[word.length()-i-1];
        	word[word.length()-i-1] = temp;
        }
}  



any help would be great. I just want to know how to put this as EOF loop and the reverse help
I'm a bit confused. You're trying to use an End of File loop, but you're not atually taking input from a file. What makes you think you need to use an EOF loop for this project? Is this supposed to take a string from a file, and then search for a character that you specify?
Oh im sorry i meant just an end loop i suppose. I figured it out.
I just put it all in a while(cin) loop. so you just use ctrl+d to end
Gotcha. :) Just remember to "tell" your user how to end the program! I always like to assume the person using the program is barely able to read, even if it is a teacher. It just helps you to write more intuitive programs later on.

Happy coding!
Topic archived. No new replies allowed.