小编Kun*_*egi的帖子

C编程strcat使用指针

我是C的初学者.我想用指针创建strcat函数.我做到了,但不知道它有什么问题.我使用gcc编译器,它给出了分段错误输出.

#include<stdio.h>
#include<string.h>

char scat(char *,char *);

void main()
{
    char *s="james";
    char *t="bond";

    char *q=scat(s,t);
    while(*q!='\0') printf("the concatenated string is %c",*q);
}

char *scat(char *s,char *t)
{
    char *p=s; 
    while(*p!='\0'){
        p++;
    } 
    while(*t!='\0'){
        *p=*t;
        p++;
        t++;
    }
    return p-s-t;
}
Run Code Online (Sandbox Code Playgroud)

c

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1