判断字符串是否为回文

//判断字符串是否为回文如:‘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;

 

             }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值