Hi,
the following code works fine, that is, strcpy effectively copies the whole string on temporal to word.
char word[20];
char temp[ ] = "hola";
cout << temporal << endl;
strcpy(word, temporal);
cout << word << endl;
However, if I try to use the heap to store the "word" array then I'm in trouble and I get copied only the first character.
char * word = new char [20];
char temporal[ ] = "hola";
strcpy(word, temporal);
cout << word << endl; // it only prints h
The question is what am I doing wrong? Is there a function to do that or do I have to write my own function? There is probably something I don't quite understand about strings but don't know what it is.
Please, any help is appreciated