C语言字符串反转的实现



#include <stdio.h>
void reverse(char *str)
{
	char *end = str;
	char temp;
	if(str)
	{
		while(*end)
			end++;
		--end;
		while(str<end)
		{
			temp = *str;
			*str++ = *end;
			*end-- = temp;
		}
	}
}
int main()
{
	char str[100];
	printf("Input a string pls:\n");
	gets(str);
	reverse(str);
	printf("After Reverse:\n%s\n",str);
	return 0;
}




你可能感兴趣的:(C语言字符串反转的实现)