Does anybody know why the variable s2 does not get printed. This code works if I am not using declaring a function, but just put the whole code in main. However, it does not print anything if I try to declare as an int function or void function. I think it's something fundamental about strings that I do not understand.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int reverseOrderString()
{
char s1[100];
char s2[100];
int counter, end, begin = 0;
printf("Type in a string\n");
gets(s1);
while(s1[counter] != '\0')
{
counter++;
}
end = counter-1;
for (begin = 0; begin < counter; begin++)
{
s2[begin] = s1[end];
end--;
}
s2[begin] = '\0';
return s2;
}
int main()
{
printf("%s", reverseOrderString());
return 0;
}