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

posted on 2012-12-28 14:31  南瓜饼  阅读(785)  评论(3编辑  收藏  举报

导航