Click to See Complete Forum and Search --> : Copy 2 Strings in a third string
remo
April 27th, 1999, 11:55 AM
hi folks
i have problem
i want to copy String_A and String_B in String_C
how can i make this????
after copy the String_C should look like STRING_ASTRING_B
the source i've tried looks like....
int SadClass::Add_To_SadString()
{
char * StringA=NULL;
if(StringC!=NULL)
{
StringA= new char[StringSize*CountRecord];
strcpy(StringA,StringC);
delete StringC;
}
StringC= new char[(int)StreamSize];
if(StringA!=NULL)
{
strcpy(StringC,StringA);
delete StringA;
}
strncpy(StringC + CountRecord * StringSize,StringB ,(int)StreamSize);
CountRecord++;
return 0;
}
please HELP.....
thanks
PeterK
April 27th, 1999, 12:17 PM
Are the strings defined as CStrings or arrays of characters?
If they are CStrings you should be able to do something like this:
String_C = String_A + String_B;
or
String_C = String_A + " " + String_B;
If they are arrays of characters try something like this:
strcpy(String_C, String_A)
strcat(String_C, String_B);
Hope this helps.
R.K.M.
April 27th, 1999, 12:19 PM
Use strcat
April 27th, 1999, 12:23 PM
Really it depends on what kind of strings you are using. If you are using CStrings simply use the + or += operator
CString a = "Hello";
CString b = "World";
CString c;
CString d = "Momma";
c = a+b; // sets c to "Hello World"
a += d; // set a to "Hello Momma"
If you are using generic character pointers you need to use the strcat function.
char* a = "Hello";
char* b = "World";
char* c;
strcpy (c,a); //sets c to "Hello"
strcat (c,b); // sets c to "Hello Word"
Finally if you are using character arrays you can do the same thing by extending the size of your array, then copying the characters from the other array over.
Make sure that you are careful not to overwrite memory as this would cause problems.
Rob P.
remo
April 27th, 1999, 12:44 PM
thanks allot
the command strcat was new for me.
now it works.
remo
April 27th, 1999, 12:45 PM
thank you
the command strcat was new for me.
now it works.
remo
April 27th, 1999, 12:46 PM
thank you peter
it was very helpfull
the command strcat was new for me.
thanks
sally
April 27th, 1999, 07:22 PM
char* a = "Hello";
char* b = "World";
char* c;
strcpy (c,a); //sets c to "Hello"
strcat (c,b); // sets c to "Hello Word"
doesn't work that well, as char* c doesn't have memory allocated to it
sally
Sally
April 27th, 1999, 07:22 PM
char* a = "Hello";
char* b = "World";
char* c;
strcpy (c,a); //sets c to "Hello"
strcat (c,b); // sets c to "Hello Word"
doesn't work that well, as char* c doesn't have memory allocated to it
sally
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.