I tried to write code using strrev()
. I included <string.h>
but still I'm getting an "undefined reference to strrev
" error.
I found that strrev()
doesn't have man page at all. Why?
Doesn't Linux support strrev()
?
strrev is non standard and deprecated function. So dont work on modern compilers..
The strrev() function is a built-in function in C and is defined in string. h header file. The strrev() function is used to reverse the given string.
Unfortunately, you cannot use strrev function here. In this case, you have to write the complete function that works the same as an inbuilt function. You might be facing the same issue while using strstr function. You can write your own code to implement strstr() function.
Correct. Use one of the alternative implementations available:
#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; }
#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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With