实验8-14:补全代码,字符串插入
【问题描述】
从键盘输入两个字符串存入char a[50]和char b[20],输入n值,将字符串b插入在字符串a下标n开始的位置。
说明:可根据需要定义其他变量。
【样例输入】
abcdef
ABC
3
【样例输出】
abcABCdef
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main()
{
char a[50];
char b[20];
int n=0,a1=0,b1=0;
gets(a);
gets(b);
scanf("%d",&n);
a1 = strlen(a);
b1 = strlen(b);
for(int i=0;i<a1-n;i++)
{
a[n+b1+i] = a[n+i];
}
for(int j=0;j<b1;j++)
{
a[n+j]=b[j];
}
puts(a);
return 0;
}
下载源文件
得分10.00 最后一次提交时间:2023-05-06 00:26:48 成功编译,但有警告信息. main.c: In function 'main': main.c:9:5: warning: implicit declaration of function 'gets' [-Wimplicit-function-declaration] gets(a); ^ /tmp/cc8Avu88.o: In function `main': main.c:(.text.startup+0x1e): warning: the `gets' function is dangerous and should not be used. 共有测试数据:2 平均占用内存:1.211K 平均运行时间:0.00284S
|