实验12-7:程序改写,字符串连接

1.实验12-7:程序改写,字符串连接

【问题描述】

将下列字符串连接程序改写为用指针实现:

#include<stdio.h>

void  catstr(char a[] , char  b[])

{  int i=0, j ; 
   while(a[i++]);
   for(j=0; b[j] ; j++ )
        a[i++] = b[j];

   a[i] = '\0' ;
}
void   main( )
{  char  a[20] , b[10];
   gets(a);gets(b);
   copystr(a , b);
   puts(a);
}

【输入形式】
a串 b串
【输出形式】
连接结果
【样例输入】

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课程已经结课,所以可能会断更一段时间。

以后有空的话,应该还会继续更新。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值