递归方法实现字符串中的字符反向排列

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int Strlen(char* str) {
	int count = 0;
	while (*str++)
	{
		count++;
	}
	return count;
}
void reverse_r(char* str)
{
	if (*str) {
		char* start = str;
		char* end = str + Strlen(str) - 1;
		char tmp = *start;
		*start = *end;
		*end = '\0';
		reverse_r(start + 1);
		*end = tmp;
	}
}
int main()
{
	char str[100];
	scanf("%s", str);
	reverse_r(str);
	printf("%s", str);	
	system("pause");
	return 0;
}

123456789
987654321请按任意键继续. . .

猜你喜欢

转载自blog.csdn.net/qq940051592/article/details/86424792
今日推荐