char *name,*nickname,*hobby;
cout<<"Please enter your name:";
cin>>name;
cout<<"Please enter your nick name:";
cin>>nickname;
cout<<"Please enter your hobby:";
cin>>hobby;
anything wrong with this as the program will stop running?
char *name,*nickname,*hobby;
cout<<"Please enter your name:";
cin>>name;
cout<<"Please enter your nick name:";
cin>>nickname;
cout<<"Please enter your hobby:";
cin>>hobby;
anything wrong with this as the program will stop running?
i'm not sure exactly what the program is doing if you code it like that, but you haven't allocated any memory for the pointers (are they perhaps all pointing to NULL prior to being allocated?).
you can either declare your variables that way, then have
or else just start off withCode:name = new char[15]; nickname = new char[15]; hobby = new char[15]; ... delete [] name; delete [] nickname; delete [] hobby;
also, since c++ does no bounds checking (in case the user enters something bigger than the memory you've allocated), i'd use getline() rather than cin so that you can control what happens if the user enters a longwinded hobby, etc.Code:char name[15]; ...
getline - C++ Reference
They point to a random memory location. You should have a look at std::string class, dynamic allocation might confuse a beginner.
erm, i actually creating a program that want user detail to generate password
can i know how to want the user to insert only words without numbers and vice verse?
You can't control what they type - you can however validate what they type after the event.
So if your prompt says "letters and NO digits", then you check for that after the input has been made. If it does contain digits, then print an error message and try again.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.