Question: Program Fill‑in‑the‑Blanks
Use VC++2010 to open the solution under the candidate folder blank1. The project of this solution contains a source program file blank1.c.In this program, the function fun() copies then rightmost charactersof the string pointed to by the formal parameter s to the character array pointed to by the formal parameter t to form a new string.If the length of the string pointed to by s is less than n, copy the whole string to the character array pointed to by the formal parameter t.
For example: the string pointed to by formal‑parameter s is abcdefgh, and the value of n is 5. After the program runs, the string in the character array pointed to by t should be defgh.
Please fill in the correct content at each underlined position in the program and delete the underlines to make the program get correct results.
Note: Part of the source code is in file blank1.c.Do not add or delete code lines, and do not change the program structure!
void fun(char *s, int n, char *t){int len, i, j = 0;len = strlen(s);/**********found**********/if(n >= len) strcpy(【1】);else {/**********found**********/for(i = len - n; i <= len - 1; i++)t[j++] = 【2】;/**********found**********/t[j] = 【3】;}}main(){char s[N],t[N]; int n;printf(”Enter a string: ”);gets(s);printf(”Enter n: ”);scanf(”%d”,&n);fun(s,n,t);printf(”The string t : ”);puts(t);}
【1】【2】【3】标准答案
-
t, s -
s[i] -
'\0' (也可以写 0)
简单解析
功能:复制字符串
s最右边 n 个字符到t;如果 n 比字符串总长度还大,直接把整个 s 全部复制过去。
-
空【1】: strcpy(t, s)strcpy(目标,源);当n >= len,代表要复制整个字符串,把 s 完整拷贝给 t。
语法:strcpy(接收字符串, 被复制的字符串),顺序不能写反。 -
空【2】: s[i]i = len‑n,这个下标就是字符串靠右 n 个字符的起始位置。
循环从这个位置,逐个取出s[i],赋值给t[j++],把右侧字符逐个搬过去。
示例"abcdefgh"len=8,n=5 →i=8‑5=3,s[3]就是字符d,从 d 开始往后取 5 个字符。 -
空【3】: '\0'
C 语言字符串结尾必须手动加字符串结束符'\0'。
循环只复制了有效字符,不会自带结束标记;不写'\0',t 就不是合法字符串,输出会乱码。'\0'等价于数字 0。
运行例子
s="abcdefgh",n=5len=8,i从 3 循环到 7:s[3]='d' s[4]='e' s[5]='f' s[6]='g' s[7]='h't 得到"defgh",末尾补上'\0'。
二级 C 填空高频考点:
① strcpy 参数顺序;②数组下标取字符串尾部;③手动给字符串加结束符 '\0',这个空出现特别多。
-
人人皆为创造者 每个人都是使用者,也是创造者;是数字世界的消费者,更是价值的生产者与分享者。在智能时代的浪潮里,单打独斗的发展模式早已落幕,唯有开放连接、创意共创、利益共享,才能让个体价值汇聚成生态合力,让技术与创意双向奔赴,实现平台与伙伴的快速成长、共赢致远。
原创应该获得永久分成 原创创意共创、永久收益分成,是东方仙盟始终坚守的核心理念。我们坚信,每一份原创智慧都值得被尊重与回馈,以永久分成锚定共创初心,让创意者长期享有价值红利,携手万千伙伴向着科技星辰大海笃定前行,拥抱硅基 生命与数字智能交融的未来,共筑跨越时代的数字文明共同体。
-
东方仙盟
东方仙盟:拥抱知识开源,共筑数字新生态
在全球化与数字化浪潮中,东方仙盟始终秉持开放协作、知识共享的理念,积极拥抱开源技术与开放标准。我们相信,唯有打破技术壁垒、汇聚全球智慧,才能真正推动行业的可持续发展。
开源赋能中小商户:通过将前端异常检测、跨系统数据互联等核心能力开源化,东方仙盟为全球中小商户提供了低成本、高可靠的技术解决方案,让更多商家能够平等享受数字转型的红利。共建行业标准:我们积极参与国际技术社区,与全球开发者、合作伙伴共同制定开放协议与技术规范,推动跨境零售、文旅、餐饮等多业态的系统互联互通,构建更加公平、高效的数字生态。知识普惠,共促发展:通过开源社区、技术文档与培训体系,东方仙盟致力于将前沿技术转化为可落地的行业实践,赋能全球合作伙伴,共同培育创新人才,推动数字经济 的普惠式增长
阿雪技术观
在科技发展浪潮中,我们不妨积极投身技术共享。不满足于做受益者,更要主动担当贡献者。无论是分享代码、撰写技术博客,还是参与开源项目维护改进,每一个微小举动都可能蕴含推动技术进步的巨大能量。东方仙盟是汇聚力量的天地,我们携手在此探索硅基生命,为科技进步添砖加瓦。
Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Don't just be the one reaping all the benefits; step up and be a contributor too. Whether you're tossing out your code snippets, hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. We're gonna team up and explore the whole silicon - based life thing, and in the process, we'll be fueling the growth of technology.
开通方法
关注我们
营销资讯:抖音运营,微信公众号运营,小红书运营
网站运营:安全、备案、申请网站,漏洞扫描,数字证书
开发:开发技巧、热点技术,人工智能,数据分析,数据优化,docker
数据服务:数据恢复,数据安全,数据融合,数据异地容灾,数据优化,数据自动备份、数据清洗
人工智能:智能物联网,智慧大屏幕,OCR,智慧刷脸,语音交互,智能机器人,数字生命,数字人,大模型,本地化,边缘化智能(手机模型)
支付:微信支付服务商,支付支付服务商,刷脸支付
安全服务:WAF安全,网安扫描,漏洞扫描,安全补丁,防火墙定制
智慧大屏:物资耗材大屏幕,单位用餐大数据,智慧场馆大屏,销售大屏幕,智慧社区大屏幕,大厅查询机,景区自助机
智慧酒店:酒店系统、酒店押金、酒店房价牌、酒店门锁、布草系统
行业软件:酒店、餐饮、便利店,美发、超市,批发,景区门票,道闸,堂食,配送系统,烘焙系统,健身,美容系统,月子中心系统
物联网:智能衣柜,足浴店衣柜,售货柜,酒店自助入住机
国产化:uos系统答疑,国产软件开发,国产服务器配置,docker
一体化:酒店一体化(闸机,酒店系统,餐饮系统,售票,布草,无人酒店,在线订房),景区一体化(门票、餐饮、住宿、押金、超市、药店、商铺租赁,通车系统,售票大厅,大屏幕,无人景区,景区自助机)

