Inserting characters in the middle of char array

后端 未结 5 1186
南方客
南方客 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:28

    If you want to move all the characters up by one, then you could do it using memmove.

    #include 
    
    char ch[15];
    
    int make_room_at = 5;
    int room_to_make = 1;
    
    memmove(
        ch + make_room_at + room_to_make,
        ch + make_room_at,
        15 - (make_room_at + room_to_make)
    );
    

提交回复
热议问题