Hello everybody!
I want to ask something that crossed my mind today about strcpy..I wrote the following piece of code and although i didn't expect it to work..it worked!
#include <iostream>
using namespace std;
int main() {
char name[20], *dname;
cout << "what's your name?: ";
cin.getline(name, 20);
strcpy(dname, name);
cout << "your name is " << dname << endl;
return 0;
}
I thought that the left parameter in strcpy had to be a pointer to an array that its size would be well known...Instead i passed as a parameter just a pointer to char and the example worked..So does it have to be just a pointer? And another thing..if i replace the array "name[20]" with a pointer to char "*name" getline doesn't work..
Thank you in advance for reading my post!