找回密码
 立即注册
搜索
热搜: 活动 通知
查看: 80|回复: 0

检测点8-18

[复制链接]

620

主题

336

回帖

1057

积分

管理员

积分
1057
发表于 2026-3-7 19:45:57 | 显示全部楼层 |阅读模式
检测点8-18

1.假设数组a的内容是字符串“hello,world.”,编写一个程序将它反转为“.dlrow,olleh”,且不得借助于另一个数组进行。
参考答案:
# include <stdio.h>

int main (void)
{
    char a [] = "hello world.", * p = a, * q = a;

    while (* q != '\0') q ++;
    q --;
    while (p <= q)
    {
        char tmp = * p;
        * p = * q;
        * q = tmp;
        p ++;
        q --;
    }

    puts (a);
}

2.自己动手编写代码实现strcpy库函数的功能。
参考答案:
char * strcpy (char * restrict s1, const char * restrict s2)
{
    char * r = s1;
    while ((* s1 ++ = * s2 ++) != '\0') ;
    return r;
}

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|鼠侠网 ( 吉ICP备19001332号 )

GMT+8, 2026-3-30 17:58 , Processed in 0.228080 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表