向字符数组中插入一个字符

    char comment[32] = "test#20170420|0420";
    char *pos = strchr(comment, '#');
    char front[32]={0};
    char back[32]={0};
    char newComment[32] = {0};
    memcpy(front, comment, pos-comment);
    strcpy_s(back, pos);
    sprintf_s(newComment, "%sC%s", front, back);
    std::cout<<newComment<<endl;

 

任何new内存都是消耗的,正确的做法是使用memcpy

posted @ 2018-11-06 19:25  pipicfan  阅读(1510)  评论(0编辑  收藏  举报