louiset 2015-08-12 17:11 采纳率: 57.1%
浏览 1522
已采纳

请问此c程序哪里出错了。。谢谢

要求将输入的两个字符串连接起来。
#include
#include
char s1[80],s2[80];
int main()
{ void f();
printf("say sth:");
gets(s1);
printf("say sth. again:");
gets(s2);
f();
}
void f()
{ int i;
strcat(s1,s2);
for(i=0;i<=80;i++)
printf("%c",s1[i]);
}

  • 写回答

3条回答 默认 最新

  • threenewbee 2015-08-12 22:05
    关注
     #include <stdio.h>
    
    char s1[80],s2[80];
    
    void f(char *a, char * b)
    {
        char * a1 = a;
        while (*a1 != '\0') a1++;
        for (char * b1 = b; *b1 != '\0'; b1++,a1++)
        {
            *a1 = *b1;
        }
        *a1 = '\0';
    }
    
    int main()
    {  
      printf("say sth:");
      gets(s1);
      printf("say sth. again:");
      gets(s2);
      f(s1,s2);
      printf("%s",s1);
      return 0;
    }
    

    say sth:hello
    say sth. again: world
    hello worldPress any key to continue

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试