IDE - CodeBlocks
Compiler - GNU GCC

Hello,

I ran into a C++ exercise has me stumped. A program is to ask for a sentance, then it splits it up into individual words and puts the sentance back together with ampersands inplace of the white space.

My program is able to take the sentance and show it split into words. However, when it goes to show the sentance with the ampersands it errors and ends with "Process terminated with status -1073741819"

I don't understand how I have errored. Any suggestions would be greatly apprecaited.

My code:
Code:
#include <iostream>
#include <cstring>

using namespace std;

int main(){
    char *p;
    char string[81];
    char string2[81];

    cout << "Input a string to parse: ";
    cin.getline(string, 81);

    p = strtok(string, ", ");   // gets first token
    strncpy(string2, p, 81);    // copies first token to string2
    strcat(string2, "&");       // concatenate string "&" to string 2
    cout << p << endl;          // print out token

    while(p != NULL){               // Do until end of sentance
        p = strtok(NULL, ", ");     // gets next token
        strncpy(string2, p, 81);    // copies token to string2
        strcat(string2, "&");       // concatenate string "&" to string 2
        cout << p << endl;          // print out token
    }

    cout << string2 << endl;        // print out string2

    return 0;