Is the strrev() function not available in Linux?

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;
}

To accurately answer your question,

Is strrev() not available on Linux?

The functions strrev() available in the string.h library. Functions strrev() including some other string functions such as like strupr(), strlwr(), strrev(), which are only available in ANSI C (Turbo C/C++) and are not available in the standard C-GCC compiler.

It’s not about the system. It is about the C compiler you are using.

References:

https://discuss.codechef.com/t/is-strrev-function-not-available-in-standard-gcc-compiler/2449

https://www.csestack.org/undefined-reference-to-strrev/


#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;
}

Tags:

C

String