Inserting characters in the middle of char array

后端 未结 5 1185
南方客
南方客 2021-01-23 03:51

I have a char array filled with some characters. Let\'s say I have \"HelloWorld\" in my char array. (not string. taking up index of 0 to 9)

What I\'m trying to do is ins

5条回答
  •  抹茶落季
    2021-01-23 04:38

    Simply do:

    #define SHIFT  1
    char bla[32] = "HelloWorld";    // We reserve enough room for this example  
    char *ptr = bla + 5;            // pointer to "World"    
    memmove(ptr + SHIFT, ptr, strlen(ptr) + 1);  // +1 for the trailing null
    

提交回复
热议问题