D
drj0nson
What is the right way of creating a string/char array and assigning to
a char* which is then used in a function call. Thought it would be
quite nice to avoid a memory leakage /core dump.
1 Header with char* x
2 Class includes header
3 In Class member function I want to :
a)conditionally create a string ie populate x
b)pass (populated) x on as a function parameter.
What is the right way of doing this for :
i) assigning string variable
ii) assigning a literal.
i) Since it's a conditional create I guess it is not a good idea to use
malloc or new.
ii) Is it ok to just have x = "some string";
a char* which is then used in a function call. Thought it would be
quite nice to avoid a memory leakage /core dump.
1 Header with char* x
2 Class includes header
3 In Class member function I want to :
a)conditionally create a string ie populate x
b)pass (populated) x on as a function parameter.
What is the right way of doing this for :
i) assigning string variable
ii) assigning a literal.
i) Since it's a conditional create I guess it is not a good idea to use
malloc or new.
ii) Is it ok to just have x = "some string";