答疑解惑必采纳 2021-07-22 14:23 采纳率: 91.3%
浏览 45
已采纳

c语言问题,补全一下我的这个代码

您将实现interject函数,该函数有三个参数:str、interject和index。您应该修改str,使字符串插入从index开始,并且str的其余部分(如果有的话)添加在interject的末尾之后。具体来说,你应该修改str,使其看起来类似于数组:{str[0], str[1], ..., str[i - 1], interject[0], interject[1], ..., interject[M], str[i], ..., str[N], '\0'}.
例如,if char str[100] = "Comp Science";当你调用interject(str, "uter", 4)时,你会将str修改为"Computer Science"。
例如,if char str[100] = " beginning ";当你调用interject(str, "New ", 0)时,你会将str修改为"New Beginnings"。
例如,if char str[100] = "结束!";当你调用interject(str,“Is nearly”,7)时,你会将str修改为“The End Is Nigh !”
img

img
#include <stdio.h>

#define MAX_SIZE 1002

// Modify str so that it contains interject at the given index.
void interject(char *str, char *interject, int index) {
// TODO: complete this function.
}

// This is a simple main function that you can use to test your interject
// function.
// It will not be marked - only your interject function will be marked.
//
// Note: the autotest does not call this main function!
// It calls your interject function directly.
// Any changes that you make to this function will not affect the autotests.

int main(void) {
char str1[MAX_SIZE] = "Comp Science";
printf("%s -> ", str1);
interject(str1, "uter", 4);
printf("%s\n", str1);

char str2[MAX_SIZE] = "Beginnings";
printf("%s -> ", str2);
interject(str2, "New ", 0);
printf("%s\n", str2);

char str3[MAX_SIZE] = "The End!";
printf("%s -> ", str3);
interject(str3, " Is Nigh", 7);
printf("%s\n", str3);

char str4[MAX_SIZE] = "UNSW Other Unis";
printf("%s -> ", str4);
interject(str4, "> ", 5);
printf("%s\n", str4);

return 0;

}

  • 写回答

1条回答 默认 最新

  • CSDN专家-link 2021-07-22 14:32
    关注

    没写完么?能把英文翻译吗?看不懂......

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 7月22日
  • 修改了问题 7月22日
  • 修改了问题 7月22日
  • 创建了问题 7月22日

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料