将字符串反向输出

(1):

#include<stdio.h>
#include<stdlib.h>
char* Rever_string(char* p)
{
	int n = 0;
	char* q;
	char temp;
	q = p;
	while (*p != 0)
	{
		p++;
		n++;
	}
	if (n > 1)
	{
		temp = q[0];
		q[0] = q[n - 1];
		q[n - 1] = '\0';
		Rever_string(q + 1);
		q[n - 1] = temp;
	}
	return q;
}
int main()
{
	char p[] = "asdfghjkl";
	printf("翻转前:%s\n", p);
	printf("翻转后:%s\n", Rever_string(p));
	system("pause");
	return 0;
}

在这里插入图片描述

(2):

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void Printf()
{
	char a;
	scanf("%c", &a);
	if (a != '#')
	{
		Printf();
	}
	if (a != '#')
	{
		printf("%c", a);
	}
}
int main()
{
	printf("请输入一个人以#结尾的字符串:\n");
	Printf();
	system("pause");
	return 0;
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43870213/article/details/84963399