C语言--编写函数,判断一个字符串是否为回文串。
源代码:
#include <stdio.h>
#include <string.h>
#define N 100
int huiwen(char* p,int len){
	char *ps,*pe;
	ps=p;
	pe=p+len-1;
	for(;ps<=pe;ps++,pe--){
		if(*ps!=*pe)
			return 0;
	}
	return 1;
}
int main()
{
	char str[N];
	printf("请输入一个字符串:");
	gets(str);
	int len=strlen(str);
	if(huiwen(str,len))
		printf("该字符串是回文串\n");
	else
		printf("该字符串不是回文串\n");
	return 0;
}
运行结果:
 
 