C语言memcpy和strncat

#include <string.h>



int main(int argc, const char * argv[])

{



    unsigned char* c=NULL;

    c = (unsigned char*)malloc(15);

    unsigned char d[5]={1,2,3,4,5};

    unsigned char e[5]={11,22,33,44,55};

    memcpy(c, d, sizeof(d));

    memcpy(c+5, e, sizeof(e));

    //strncat(c, d, sizeof(d));

    //strncat(c, e, sizeof(e));

    for (int i=0; i<15; i++) {

        printf("c[%d] is %d\n",i,c[i]);

    }

    free(c); 

    return 0;

}

输出:

c[0] is 1

c[1] is 2

c[2] is 3

c[3] is 4

c[4] is 5

c[5] is 11

c[6] is 22

c[7] is 33

c[8] is 44

c[9] is 55

c[10] is 0

c[11] is 0

c[12] is 0

c[13] is 0

c[14] is 0

你可能感兴趣的:(C语言)