Why this code is crash?

Hi
Code is crash unexpectedly, any logical error in this code?
Purpose of this code is to reverse the string.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *s[]={"To err is hman..",
"man is wild",
"Dream big thought",
"do it myself self",
};
void xstrrev(char *a1,char *a2,char *a3,char *a4)
{
   strrev(a1);
   strrev(a2);
   strrev(a3);
   strrev(a4);
}
int main()
{
 for(int i=0;i<4;i++)
    {
        printf("%s\n",s[i]);
    }

    printf("Hello world!\n");
    xstrrev(s[0],s[1],s[2],s[3]);
    for(int i=0;i<4;i++)
    {
        printf("%s\n",s[i]);
    }
    return 0;
}

That is NOT Arduino code!

Sorry. I understood.

i got the following

.. namuh si rre oT
dliw si nam
thguoht gib maerD
fles flesym ti od
 - done

when i used setup() and loop()

const char *s[]={
    "To err is human ..",
    "man is wild",
    "Dream big thought",
    "do it myself self",
};

void xstrrev (
    char *a1,
    char *a2,
    char *a3,
    char *a4 )
{
    strrev(a1);
    strrev(a2);
    strrev(a3);
    strrev(a4);
}

void setup (void)
{
    Serial.begin (9600);

    for(int i=0;i<4;i++)
    {
        strrev ((char*) s[i]);
        Serial.println (s [i]);
    }
    Serial.println (" - done");
}

void loop (void) {
}

Part of the problem is writing into string constants (pointers to constant characters).

/Users/john/Documents/Arduino/sketch_nov24a/sketch_nov24a.ino:8:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
             };
             ^
/Users/john/Documents/Arduino/sketch_nov24a/sketch_nov24a.ino:8:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
/Users/john/Documents/Arduino/sketch_nov24a/sketch_nov24a.ino:8:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
/Users/john/Documents/Arduino/sketch_nov24a/sketch_nov24a.ino:8:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

If you fix those by changing "char *s" to "const char *s". Then the warnings jump to the call to xstrrev() where you are passing "const char *" to a function that takes "char *".

If you fix that by changing the declaration to:

void xstrrev(const char *a1, const char *a2, const char *a3, const char *a4)

THEN the warnings appear on the calls to "strrev()" where you are passing "const char *" to a function that takes "char *". Since strrev() modifies the characters, you can't change it to say that it doesn't.

Using a 'const char *' as a 'char *' is usually a mistake, which is why you get a warning and why it is invalid code in ISO C++. The way to do it without warnings is to use initialized character arrays. You are free to write whatever you want into your own character arrays:

char s1[] = "To err is hman..";
char s2[] = "man is wild";
char s3[] = "Dream big thought";
char s4[] = "do it myself self";


char *s[] = {s1, s2, s3, s4};