I see a very interesting code to reverse a string, but I don't understand here:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void Reverse(char *s);
int main()
{
char *s=NULL;
s=(char *)malloc(sizeof(char *));
gets(s);
Reverse(s);
puts(s);
return 0;
}
void Reverse(char *s)
{
char *end=s;
char tmp;
if (s)
{
while (*end)
{
++end;
}
--end;
while (s<end) ??
{
tmp=*s;
*s++=*end;
*end--=tmp;
}
}
}
I see the this program tries to work on the same string by using end=s to change both string at the same time, but what does '*' line : while(s<end)
here mean?
I use gdb and find that when we input asdfgh
, when *s is fdsa and *end is fds, this is no longer true, how this line controls the program?
I just want to know what '??' line mean..
Thanks a lot !