+ 5
I got the error "undefined reference to strrev".How could i remove this?
13 ответов
+ 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;
}
+ 12
Can you share your code?
+ 12
I don't get the error /:
+ 8
Thanks😊 Boub Fixer🇺🇬
+ 5
thanks...Mohamed ELomari
+ 4
i got error when i was compiling it on hackerearth .
+ 4
i was coding on hackerearth terminal
+ 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;
}
+ 2
yesValen.H. ~
+ 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;
}
+ 2
strrev are not available in standard C-GCC compiler, you have to write the complete function that works same as an inbuilt function
+ 2
this could also be because your devise must be old or webview is old version
0
What is the use of the condition
!str || !*str