#include <stdio.h>
#include <string.h>
char *reverse(char *str)
{
char tmp, *src, *dst;
size_t len;
if (str != NULL)
{
if (len > 1)
{
src = str;
dst = src + len - 1;
while (src < dst)
{
tmp = *src;
*src++ = *dst;
*dst-- = tmp;
}
}
}
return str;
}
int main(int argc, char *argv[])
{
char *str[] = {"a", "ab", "abc", "test", "another test"};
int i;
char s[10000];
for (i=0; i < sizeof(str) / sizeof(str[0]); i++)
{
printf("Original: '%s'\n", str
[i
]); printf("Reversed: '%s'\n", reverse
(s
)); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCmNoYXIgKnJldmVyc2UoY2hhciAqc3RyKQp7CiAgICBjaGFyIHRtcCwgKnNyYywgKmRzdDsKICAgIHNpemVfdCBsZW47CgogICAgaWYgKHN0ciAhPSBOVUxMKQogICAgewogICAgICAgIGxlbiA9IHN0cmxlbihzdHIpOwogICAgICAgIGlmIChsZW4gPiAxKQogICAgICAgIHsKICAgICAgICAgICAgc3JjID0gc3RyOwogICAgICAgICAgICBkc3QgPSBzcmMgKyBsZW4gLSAxOwoKICAgICAgICAgICAgd2hpbGUgKHNyYyA8IGRzdCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdG1wID0gKnNyYzsKICAgICAgICAgICAgICAgICpzcmMrKyA9ICpkc3Q7CiAgICAgICAgICAgICAgICAqZHN0LS0gPSB0bXA7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gc3RyOwp9CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKQp7CiAgICBjaGFyICpzdHJbXSA9IHsiYSIsICJhYiIsICJhYmMiLCAidGVzdCIsICJhbm90aGVyIHRlc3QifTsKICAgIGludCBpOwogICAgY2hhciBzWzEwMDAwXTsKICAgIGZvciAoaT0wOyBpIDwgc2l6ZW9mKHN0cikgLyBzaXplb2Yoc3RyWzBdKTsgaSsrKQogICAgewogICAgICAgIHN0cmNweSAocywgc3RyW2ldKTsKICAgICAgICBwcmludGYoIk9yaWdpbmFsOiAnJXMnXG4iLCBzdHJbaV0pOwogICAgICAgIHByaW50ZigiUmV2ZXJzZWQ6ICclcydcbiIsIHJldmVyc2UocykpOwogICAgfQogICAgcmV0dXJuIDA7Cn0K