The main idea of this code is to work in two passes:
:
char *end = str;
while (*end) {
++end;
}
--end;
while end, . end , *end true. C , true, end - , . , , end . --end . end . "Hello:"
H e l l o
^ ^
| |
str end
, end, . :
while (str < end) {
tmp = *str;
*str++ = *end;
*end-- = tmp;
}
, , , , , .
while (str < end) {
tmp = *str;
*str = *end;
*end = tmp;
++str;
--end;
}
, . , , . :
H e l l o
^ ^
| |
str end
o e l l H
^ ^
| |
str end
o l l e H
^
|
str end
, .
, , , . , . , :
char *end = str;
while (*end) {
++end;
}
--end;
, end . , , end ! , undefined . , , , :
while (str < end)
, end - , .
, !