If you try it:
void reverse(char *s1){
char a[100];
char *s2;
int i=0;
s2=&a[0];
while(*s1!='\0'){
s1++;
i++;
}
s1--;
i--;
while(i>=0){
*s2=*s1;
s2++;
s1--;
i--;
}
printf("%s\n", a);
}
int main()
{
char s[] = "Hello World!";
printf("%s\n", s);
reverse(s);
return 0;
}
Then you get the result:
Hello World!
!dlroW olleH
But ... that's probably more by luck than by judgement. The problem is that you aren't copying the string termination character '\0' from your input to your output, as is easy to prove, by "pre filling" the array with identifiable rubbish:
char *s2;
int i=0;
for (i = 0; i < 100; i++)a[i] = 'X';
i = 0;
Now when you print you get:
Hello World!
!dlroW olleHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX����l7n��
Because there is nothing in the output string to tell printf when to stop!
Either set a null at the end of the reversed string, or prefill "a" to all nulls.
I'd do this differently though, with just a single loop:
int *inp = s1;
int *outp = &(a[99]);
do
{
copy from inp to outp
if (inp was a null or you run out of space) exit the loop
inc inp, dec outp
} while (true);
You then print the reversed string directly from outp
Be aware that this function is useless unless you return the reversed string - but you can;t return a or any pointer to a part of it - it's on the stack and will cause major problems if you do. You would need to use malloc to allocate the space, not declare the array on the stack - and then arrange to free it. It would be a better idea to pass both the string and the output area to the function.