Having trouble using the keyword new inside of a function when passing a pointer in.
I am having trouble using the keyword new inside of a function when passing a pointer in to it. Please tell me what I am doing wrong.
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
struct person_details{
char name[100];
char phone[100];
};
void getDetails( person_details * pd ){
pd = new person_details[1];
strcpy( pd[ 0 ].name, "John Doe" );
}
int main(int argc, char *argv[])
{
person_details *pDetails = 0;
getDetails( pDetails );
cout << "pDetails[ 0 ].name " << pDetails[ 0 ].name << endl;
delete pDetails;
system("PAUSE");
return EXIT_SUCCESS;
}