Here is the way how I can display the string "dcba":
main()
{
char s[10] = "abcd";
puts(strrev(s));
}
The way how I get a "Segmentation Fault" (why?):
puts(strrev("abcd"));
And here is the function that reverse the string:
char *strrev(char *s)
{
int i, j;
char aux;
for(i=0, j=strlen(s)-1; i<j; i++, j--)
{
aux = s[j];
s[j] = s[i];
s[i] = aux;
}
return s;
}