| vibol03 (1) | |||
|
i've been trying to write a function that would return a char pointer which is made up of repeated characters. The thing is i can only use c string function.
can anyone point out my mistake please? i am new to c++ and this char array thing kinda throw me off big time. Thank you | |||
|
|
|||
| Stewbond (1670) | |||
|
You don't initialize pChar. Try this:
| |||
|
Last edited on
|
|||
| pogrady (410) | |
|
A char pointer is just that: a pointer to a char sized memory location. So when you define char* pChar; You are just declaring a pointer object with no useful data in it. You'll need to do this: char* pChar = new char; This declares a char pointer that is filled with a useable object. The problem is that the object is one byte in length, and you need more then that. If you don't remeber, this is how you declare an array: char* pChar = new char[]; With the number of elements in the brackets. | |
|
Last edited on
|
|