The line pfish->kind = "guppy" produces an error statement: "invalid array assignment." Why does this happen when I'm assigning the address of the first char element ('g') to the array of chars in the structure pointed to by pfish?
1 2 3 4 5 6 7 8 9
struct fish
{
char kind[6];
int weight;
double length;
};
fish* pfish = new fish;
pfish->kind = "guppy";
cout << pfish->kind <<"\n";
You cannot assign to a character array. I recommend using std::string instead, but if you can't, use strcpy or use a character pointer instead of a character array.
Since you named it "kind", I may also suggest looking into OOP and Polymorphism, or else using an enum instead of a string.