Look at your code.
char reversestring(char* t)
{
...
char r[100];
...
return r;
}
And
char s[100],r[100];
...
r[100]=reversestring(t);
So what - exactly - is
reversestring
returning? Is it a char? No - it's an array of chars, which is a pointer-to-char.
And where do you store this? In a pointer-to-char? No, you try to put a pointer into an array at index 100, which is not even inside the array because C arrays start from index zero.
Start by correcting the code so
reversestring
returns the right type: pointer-to-char.
Then stop what you are doing and learn about
dangling references
- which is what returning
r
would be: it's a local array, so it only exists as long as your function is running. if your return a pointer to local memory, you will get problems later. So change your
reversestring
function to take two parameters: the input array and the output array, and then return the output array.
Finally, don't store the result in a single element of the array! Store it in a pointer-to-char variable instead!