[Solved] issues retrieving character array data


You can’t copy a C string using assignment to the pointer, you need to use strcpy().

void setname(string n) {
    if (n.size() >= sizeof name) {
        cout << "Name " << n << " is too long\n";
    } else {
        strcpy(name, n.c_str());
    }
}

Also,

ptr = &name[30];

is a pointer to beyond the end of the name array. The last element of the array is name[29].

2

solved issues retrieving character array data