C语言 字符串逆序 函数 strrev()

版权声明:走过路过的,如果发现有错误不妥的地方,烦请指正,不胜感激。 https://blog.csdn.net/jsx_SEVEN/article/details/90273007

头文件

#include <string.h>

函数原型

char *strrev(char *str);

功能

把字符串str的所有字符的顺序颠倒。(逆序)

示例

#include <stdio.h>
#include <string.h>

int main()
{
	//char *a = "asdfg";  
	//printf("%s", strrev(a));     //用法错误
	                               //strrev()不会生成新的字符串,只是修改传入的字符串
	                               //字符指针指向的是字符串常量,不能修改
	                               //所以,只能反转字符数组,不能反转字符指针指向的字符串
	
	//正确用法一
	char b[] = "abcde";
	printf("%s",strrev(b));

	//正确用法二
	char c[] = "wxyz";
	char *d = c;
	printf("%s", strrev(d));
}

猜你喜欢

转载自blog.csdn.net/jsx_SEVEN/article/details/90273007