#include <stdio.h>
char *swap_str(char *str)
{
int i, tmp, max;
i = 0;
while (str[i] != '\0')
i++;
max = i;
for (i = 0; i < (max >> 1); i++)
{
tmp = str[i];
str[i] = str[max - i - 1];
str[max - i - 1] = tmp;
}
return str;
}
int main()
{
char str1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char str2[] = "9876543210";
printf(">>%s\n", str1);
printf("=>%s\n", swap_str(str1));
printf(">>%s\n", str2);
printf("=>%s\n", swap_str(str2));
return 0;
}
[output]:
>>ABCDEFGHIJKLMNOPQRSTUVWXYZ
=>ZYXWVUTSRQPONMLKJIHGFEDCBA
>>9876543210
=>0123456789
沒有留言:
張貼留言