C语言中strcat的用法

来源:互联网 发布:mysql必知必会 编辑:程序博客网 时间:2024/05/01 03:35

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

int main(void)

{

    char *s;

    char *t;

    char *r;

 

    s = "abc";

    t = "def";

    r = (char*)(malloc(strlen(s) + strlen(t) + 1));

 

    if(!r)

    {

          printf("fail/n");

          return 0;

    }

 

    strcpy(r,s);

    strcat(r,t);

 

    printf("%s/n",r);

 

    if(r != NULL)

    {

           free(r); 

           r = NULL;

    }

 

    system("pause");

    return 0;

}

原创粉丝点击