简体   繁体   中英

Verifying if string S is equal to string T backwards

For example, if I first enter testing and then that same word backwards, which is gnitset , it should print that the statement is true. I'm not sure what's wrong with my program since I just started with the strrev function and strings in general.

#include <stdio.h>

int main()
{
   char wordS[101], wordT[101];

   scanf("%s", wordS);
   scanf("%s", wordT);

  if (wordS == strrev(wordT)){
    printf("true");
}   
  else printf("false");

return 0;
}

wordS == strrev(wordT) compares pointers but not the string. Use strcmp instead.

if (strcmp (wordS ,strrev(wordT)) == 0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM