为了账号安全,请及时绑定邮箱和手机立即绑定

为什么不能连续的进行复制,在处理字符串时。

#include <stdio.h>
#include <string.h>
int main()
{
    char s1[100];
    char s2[]="我爱,";
    char s3[]="慕课网";
    strcat (s2,s3);
    strcpy (s1,s2);
    printf("%s\n",s1);
    return 0;
    }为什么s1不能输出结果

正在回答

2 回答


#include <stdio.h>
#include <string.h>
int main()
{
    char s1[100];
    char s2[]="我爱,";
    char s3[]="慕课网";
    strcpy(s2,s3);
    strcat(s1,s2);
    printf("%s\n",s1);
    return 0;
    }

注意,char s2[]里需要字符长度,你没给他,所以可以在里面加个长度

           char s2[20];  这样就行。


0 回复 有任何疑惑可以回复我~

#include <stdio.h>
#include <string.h>
int main()
{
    char s1[100];
    char s2[]="我爱,";
    char s3[]="慕课网";
    strcpy(s1,s2);
    strcat(s1,s3);
    printf("%s\n",s1);
    return 0;
    }

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么不能连续的进行复制,在处理字符串时。

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号