Click to See Complete Forum and Search --> : C++ Question


salientking
02-13-2007, 02:22 AM
SO ive received some old hand me down code that i want to use, but I've avoided C++ for awhile now and have no idea how to do what i want to do

First off i have a union, and i want to pass this union a ptr to a string. But i need to edit this string before i can send it over, and im using the string.h header.

Say the string var contains "stuff"
I want to remove the qoutes
So i was thinking taking var+1 and storing that into another var
so var2 = var+1 = stuff"
But then how to i replace the second " with a end line char?
Then i need to pass a ptr to the newly edited string to the union

Also im a little lost with the whole passing a ptr/memory allocation deal with c++ strings.

russell
02-15-2007, 04:43 PM
do the replacing in a function. pass a pointer to the original string.

should have a look at This (http://www.cplusplus.com/reference/clibrary/cstring/)

pointers become a lot easier to understand if u think of it like this:

passing a pointer to a variable allows the original variable to be modified. this is called "pass by reference"

passing the variable itself does not allow the original copy to be modified (unless you are assigning it as the return value of the function). this is called "pass by value"

pointer syntax may be tricky, but stop to take the time to understand pointer logic. it is actually rather easy once it sinks in.