您将实现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 !”
#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;
}