I have problem with my code i cant assign a string value into char* in a struct. Can someone tell me what is wrong with my code and why?
#include <iostream>
using namespace std;
typedef struct{
char* name;
char* city;
int age;
} person;
void main()
{
person * user;
user = (person*)malloc(sizeof(person*));
cout << "Please fill in the user info.." << endl << "Name: ";
cin >> user->name;
cout << "Age: ";
cin >> user->age;
cout << "City";
cin >> user->city;
cout << "The user info is:" << endl << "Name: " << user->name << endl << "Age: " << user->age << endl << "City: " << user->city << endl;
system("pause");
}
Thank you very much.
See Question&Answers more detail:os