assign const char* inside nested struct (c++)

Thursday, July 10, 2014

im trying to assign a const char* value inside a nested structure. I want to assign the name and firstname to a char value, not to a string. this is more c i know, but im using c++. Here is my problem:



struct person {
const char* name;
const char* firstname;
};


struct person_struct {
int pers_num;
struct person* data;
};

// How does the assignment work?... i know this is wrong:
char name[100] = "Jason";
char firstname[100] = "Conner";
struct person_struct;
person_struct.pers_num = 1;
person_struct->data->name = new char[strlen(name)+1];
person_struct->data->firstname = new char[strlen(firstname)+1]


Thanks so much for your help, all of you!!! :-)







http://ift.tt/1k8iuGx