#include <iostream>
#include <algorithm>


void insert_blank(char* line, std::size_t line_size, std::size_t pos)
{
    std::size_t index = 0;
    while (line[index++])
        ;

    if (index + 1 >= line_size || pos >= index) // sanity check
        return;

    while (index != pos)
    {
        line[index] = line[index - 1];
        --index;
    }

    line[index] = ' ';
}

std::istream& get(std::istream& is, int& val)
{
    // get a number and remove the trailing newline.
    return (is >> val).ignore(100, '\n');
}

int main()
{
    const char* prompt = "Enter a string (or just hit <ENTER> to quit)\n> ";

    const std::size_t buffer_size = 1024;
    char line_buffer[buffer_size];

    while (std::cout << prompt && std::cin.getline(line_buffer, buffer_size-1) && line_buffer[0])
    {
        const char* prompt = "Enter the position to insert blank (or negative to quit)\n> ";

        int position;
        while (std::cout << prompt && get(std::cin, position) && position >= 0)
        {
            insert_blank(line_buffer, buffer_size, position);
            std::cout << "modified: \"" << line_buffer << "\"\n";
        }

    }
}