几道笔试题的解法(六)

论坛 期权论坛 脚本     
匿名技术用户   2020-12-29 22:26   211   0

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

分析:本题考查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;

}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP