Write a function that takes a char* argument. Using new,
dynamically allocate an array of char that is the size of
the char array that’s passed to the function. Using array
indexing, copy the characters from the argument to the
dynamically allocated array (don’t forget the null
terminator) and return the pointer to the copy. In your
main( ), test the function by passing a static quoted
character array, then take the result of that and pass it
back into the function. Print both strings and both
pointers so you can see they are different storage. Using
delete, clean up all the dynamic storage.
When I try to compile this, I get an error on line 13 saying that the initializer is failing to determine the size of d. I'm not sure what this means or how to fix it. Could someone explain?
EDIT: changed sizeof(*) to sizeof(*a) as in the original code
Ok, you seem to not really understand what the assignment wants...and also you don't understand how pointers work. I would re-read whatever book you have's pointer section and also re-read the assignment question, specifically:
Using array indexing, copy the characters from the argument to the dynamically allocated array
I can't seem to get it close to working. My main problem right now is what do I put in the brackets in new char[]? How can I know the size of the array passed to the function?