1. 程式人生 > >實現字串翻轉(逆序輸出)

實現字串翻轉(逆序輸出)

#include 
#include 
void swap(char *a, char *b)
{
	assert(a);
	assert(b);
	*a = *a^*b;
	*b = *a^*b;
	*a = *a^*b;
}
void switchstring(char *str)
{
	assert(str);
	char *start = str;
	char *end = str + strlen(str) - 1;
	while (start < end)
	{
		swap(start, end);
		start++;
		end--;
	}
}
int main()
{
	char str[] = "abcdef";
	switchstring(str);
	printf("%s\n", str);
	return 0;
}