+ 5

I got the error "undefined reference to strrev".How could i remove this?

16th Jun 2018, 4:36 PM
Crystal!!!😎
Crystal!!!😎 - avatar
13 Answers
+ 4
The strrev() function and some other string functions are only available in Turbo C/C++ which uses ANSI C and are not available in the standard C-GCC compiler. Alternatively, you could write this function in your code: #include<string.h> char *strrev(char *str) { if (!str || ! *str) return str; int i = strlen(str) - 1, j = 0; char ch; while (i > j) { ch = str[i]; str[i] = str[j]; str[j] = ch; i--; j++; } return str; } //——————————— //or //——————————— #include<string.h> char *strrev(char *str) { char *p1, *p2; if (! str || ! *str) return str; for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) { *p1 ^= *p2; *p2 ^= *p1; *p1 ^= *p2; } return str; }
11th Sep 2019, 7:07 PM
Tusiime Innocent Boub
Tusiime Innocent Boub - avatar
+ 12
Can you share your code?
16th Jun 2018, 4:37 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 12
I don't get the error /:
16th Jun 2018, 4:56 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 8
12th Sep 2019, 2:21 AM
Crystal!!!😎
Crystal!!!😎 - avatar
+ 5
16th Jun 2018, 5:45 PM
Crystal!!!😎
Crystal!!!😎 - avatar
+ 4
i got error when i was compiling it on hackerearth .
16th Jun 2018, 5:05 PM
Crystal!!!😎
Crystal!!!😎 - avatar
+ 4
i was coding on hackerearth terminal
23rd Jun 2018, 1:34 PM
Crystal!!!😎
Crystal!!!😎 - avatar
+ 3
here is an alternative to it: #include<string.h> char* strrev(char *str) { if (! str || ! *str) return str; for (char *p1_str = str, *p2_str = str + strlen(str) - 1; p2_str > p1_str; ++p1_str, --p2_str) { *p1_str ^= *p2_str; *p2_str ^= *p1_str; *p1_str ^= *p2_str; } return str; }
16th Jun 2018, 5:38 PM
MO ELomari
MO ELomari - avatar
16th Jun 2018, 4:45 PM
Crystal!!!😎
Crystal!!!😎 - avatar
+ 2
#include <stdio.h> #include<string.h> int main() { char s[50],b[50]; scanf("%s",s); strcpy(b,s); strrev(b); if(strcmp(s,b)==0) { printf("palindrome"); } else { printf("Not palindrome"); } return 0; }
16th Jun 2018, 4:46 PM
Crystal!!!😎
Crystal!!!😎 - avatar
+ 2
strrev are not available in standard C-GCC compiler, you have to write the complete function that works same as an inbuilt function
16th Jun 2018, 5:29 PM
MO ELomari
MO ELomari - avatar
+ 2
this could also be because your devise must be old or webview is old version
23rd Jun 2018, 9:18 AM
Alex
Alex - avatar
0
What is the use of the condition !str || !*str
3rd Jun 2020, 6:08 PM
Jafar Sadiq Shaik
Jafar Sadiq Shaik - avatar