1. | 实验12-7:程序改写,字符串连接 【问题描述】 将下列字符串连接程序改写为用指针实现: #include<stdio.h> void catstr(char a[] , char b[]) { int i=0, j ; a[i] = '\0' ; 【输入形式】 hello world
helloworld |
---|
#include<stdio.h>
#include<string.h>
void catstr(char *a , char *b)
{
strcat(a,b);
puts(a);
}
int main( )
{ char a[20] , b[10];
char*pa,*pb;
pa=a;pb=b;
gets(a);
gets(b);
catstr(pa,pb);
return 0;
}
得分10.00 最后一次提交时间:2023-06-09 18:42:58
成功编译,但有警告信息.
main.c: In function 'main':
main.c:13:4: warning: implicit declaration of function 'gets' [-Wimplicit-function-declaration]
gets(a);
^
/tmp/ccSSfP63.o: In function `main':
main.c:(.text.startup+0xc): warning: the `gets' function is dangerous and should not be used.
共有测试数据:2
平均占用内存:1.211K 平均运行时间:0.00261S
测试数据 | 评判结果 |
测试数据1 | 完全正确 |
测试数据2 | 完全正确 |
因为题目中答题模块可以自己删改,所以,为了方便起见,我选择直接使用<string.h>中的strcat语句直接完成。
本学期的C课程已经结课,所以可能会断更一段时间。
以后有空的话,应该还会继续更新。