ok how do i copy two variables let say
char x[30]
and
char y[30]
into
char z[30]
??
Damn i know this is easy but i cant find anything on this.
Help is greatly appreciated!
ok how do i copy two variables let say
char x[30]
and
char y[30]
into
char z[30]
??
Damn i know this is easy but i cant find anything on this.
Help is greatly appreciated!
do you want to add the two variables, or copy the stuff in memory into the new array...
add two variables, like shown...
z[30] = x[30] + y[30];
if you want to copy them...you can't stick both in z[30]
it would have to be something like;
z[0] = x[30];
z[1] = y[30];
hope this helps...
no not really
i want to put two different strings into one variable
pretty much
x[30]="hello";
y[30]="bob"
and i want
z[30]="hellobob";
does anyone know how to do this
i know it has something to do with strcpy but i have no clue!
Well to do what you want to do, youd have to actaully make sure x and y combined are less then 30.
It would be better if you found out how many characters were in x and y, and add that together to be the new Z[length].
c++->visualc++->directx->opengl->c++;
(it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)
okay aafter i do that what do i do?
If you use the <string> header you can just add the strings together.
string h="hello";
string w="world";
string hw=h+w;
My Avatar says: "Stay in School"
Rocco is the Boy!
"SHUT YOUR LIPS..."
or if you're looking to do it with the char arrays try sprintf() or strcat()
hello, internet!
no im not using arrays
ok using rods method how would i then store string hw into a variable lets say name?
string hw - IS A VARIABLE no need to store it anywhere it's already stored.
hw now equals:Code:string h="hello"; string w="world"; string hw = h + w; // This equals "helloworld" //Now watch this, hw=h+" "+w+" "+",did you know that this string variable can hold large strings and you can add them together with a \'+\' sign.";
"hello world ,did you know that this string variable can hold large strings and you can add them together with a '+' sign."
My Avatar says: "Stay in School"
Rocco is the Boy!
"SHUT YOUR LIPS..."
okay i get all of this but now i want to put string hw into my variable vars.fullName for my structure
how would i do that?
ah hah i got it
i was under the impression that u cannot declare strings in a function
o well i figured it out!
Yes, it needs to be of the same type - your var must be a string or you'll be forced to do some TRIXXX to make it work.
My Avatar says: "Stay in School"
Rocco is the Boy!
"SHUT YOUR LIPS..."
sure looked like you were a few posts agoOriginally posted by dizz
no im not using arrays
ok using rods method how would i then store string hw into a variable lets say name?
you sure you have a handle on whatever it is you're asking?
hello, internet!
yeah thats cuz instead of using char arrays i just chose to use strings
x[30]="hello";
y[30]="bob"
and i want
z[30]="hellobob";Does this do the job.Code:strcat(z, x); strcat(x, y);