//判断字符串是否为回文如:‘123321’两边对称的字符串
#include <stdio.h>
#include <string.h>
#define DEBUG//调试用
/***************/
#ifndef FUNCTIONS
#define FUNCTIONS
///
char * BeginToEnd (const char * str , char * temp)
// 作用:temp放入 str的反序字符串
{
int i= strlen(str) ;
int j= -1;
int itemp = i;
#ifdef DEBUG
printf("strlen(str):%d",i);
#endif
while( --i > -1 && ++j <= itemp )
{
temp[j] = str[i] ;
#ifdef DEBUG
printf("/t%c:%c",str[i],temp[j]);
#endif
}
temp[++j] = str[strlen(str)];
#ifdef DEBUG
printf("/n %s : %d.%d.. :%c/n",temp, j,i , str[strlen(str)] );
#endif
return temp;
}
/
void FreeStr(char * ptr)
{
free(ptr);
return;
}
///
int CheckHuiWen(const char * const str)
//判断str是否为 ‘回文’
{
int i;
char* temp= (char *)
malloc ( sizeof(char)*( strlen(str)+1 ) ) ;
/*strncpy(temp , str, strlen(str)+1); */
BeginToEnd(str,temp);
i= strcmp(str , temp );
FreeStr(temp);
return i;
}
#endif
/****************************/
/************test******************/
void main(void)
{
char *testStr;
printf("input string :");
scanf("%s",testStr);
switch ( CheckHuiWen( testStr ) )
{
case 0: {
printf("%s HuiWen ...",testStr );
break;
}
default:{
printf("%s ! isn't HuiWen ... ",testStr );
}
}
return;
}