why does this if statement not execute?

This is just a small program that i wrote to change any 'e's in a string to be changed to an 'E' but the quit option i wrote doesn't seem to work.

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
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int i;
    char ch;
    char str[80];
    
    for(;;)
      {
         cout << "Please enter a string containing the letter 'e' " <<
         "('q' to quit): ";
         gets(str);
         
         if(str == "q") break;
         else
           {
    
            for(i=0; i<=80; i++)
             {
               ch = i;
               if(str[ch] == 'e')
               str[ch] = 'E';
             }
           }
          
      cout << "\n\n" << "New statement is: " << str << "\n\n";
      }
    
    cin.get();
    return 0;
}


Can anyone give me any clues please?

Thanks, Alan.
line 18: with C string use C functions, you are there camparing two pointers
http://www.cplusplus.com/reference/clibrary/cstring/strncmp.html
http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html

line 22: for(i=0; i<=80; i++) should be for(i=0; i<80; i++)
Last edited on
Thankyou :) It works perfectly now
Topic archived. No new replies allowed.