I am having problems with an assignment using a dynamic array of chars and pointers. I am supposed to create a dynamic array, fill the array using pointers, and then delete the array. Every time I run the code below, I get a Heap Corruption error. Could anybody point me to what I am doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
constint MAXNAME = 10;
int pos;
char * title;
title = newchar(MAXNAME);
cout << "Enter a title with exactly 10 characters." << endl;
for (pos = 0; pos < MAXNAME; pos++)
*(title + pos) = cin.get();
cout << "The title is ";
for (pos = 0; pos < MAXNAME; pos++)
cout << *(title + pos);
cout << endl;
delete[] title;
Geez, I can't believe I missed that. That fixed the problem. I wish it hadn't compiled, I probably would have found the problem sooner. Thanks for the help!