几道笔试题的解法(六)

来源:互联网 发布:淘宝客服考试试题2017 编辑:程序博客网 时间:2024/04/30 01:53

题目:输入一个字符串,将它逆向输出。

分析:本题考查C语言的指针。

 

代码如下:

 

int GetLength(const char* _in)

{

   int _length = 0;

   while (*_in++ != '/0')

   {

      _length++;

   }

 

   return _length;

}

char* StringReverse(const char* _source, char* _dest)

{

   int strLength = GetLength(_source);

 

   for (_dest += strLength, *(_dest + 1) = 0; strLength > 0; strLength--, _dest--)

   {

      *_dest = *_source++;

   }

 

   return _dest + 1;

}