Heart pun

I wanted to know why strrev(a) with a a equal consideration.(so says the heart of the pun is 12345) (if such is not my fault that Google Translate)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//3.4-heart.cpp
#include <iostream>
#include <cstring>
using namespace std;

int main(){
    char a[50];
    cin>> a;
    if(strlen(a)%2!=0)
        if(a==strrev(a))
            cout<<"YES ,Pun is the heart";
        else
            cout<<"NO ,no Pun heart";
    else
        cout<<"NO ,no Pun heart";
return 0;
}
Last edited on
I'm guessing this is a palindrome finder.

It's wrong.

a is a char pointer.
strrev(a) probably returns a char pointer. strrev is NON-STANDARD so it could be doing anything at all.

Comparing the memory address of the start of two char arrays (which could be the same array, depending on what the non-standard function strrev does) is not the same as comparing the letters in the arrays.

I think this sample code is what you're trying to do:
http://www.warpspeed.com.au/cgi-bin/inf2html.cmd?..\html\book\Toolkt40\XPG4REF.INF+275

Note the difference in how the comparison is done. Then stop using char arrays and use proper C++ string objects.
Last edited on
...did you use Google Translate? It is bad at translating. What language do you speak?
Topic archived. No new replies allowed.