|
-
May 15th, 2002, 03:52 PM
#1
Thread Starter
Addicted Member
Combining to char arrays (very easy question)
let's say i want to combine CharArray1 and CharArray and i want to add "hi this is a string" aswell. How should i do this. From what i understand now i need to count the space i need, make a new array and fill it. I dont have a clue how to (the filling).
Thnx
-
May 15th, 2002, 04:37 PM
#2
Here is an example.
Code:
char szString1[] = "First character array";
char szString2[] = "Second character array";
char * lpszFullString = NULL;
lpszFullString = new char[ strlen( szString1 ) + strlen( szString2 ) + strlen( "Third String" ) + 1 ];
strcpy( lpszFullString, szString1 );
strcat( lpszFullString, szString2 );
strcat( lpszFullString, "Third String" );
std::cout << lpszFullName << std::endl;
delete [] lpszFullName;
-
May 15th, 2002, 07:42 PM
#3
Thread Starter
Addicted Member
thnx dude that really helped. I got it working perfectly now except for 1 tiny /n that i should get ridd off. If i remember corectly there's a function to remove it from the end of a string right? I couldn't find it though.... I already tried to do it with substrings (that's how i did it with VB ) Do you know a good way?
Thnx!
-
May 15th, 2002, 08:09 PM
#4
Remove the end?
Code:
char szString[] "MacDonald, Andrew
char szStrToRemove[] = "An";
char * lpszTemp = strstr( szString, szStrToRemove );
if( lpszTemp )
*lpszTemp = '\0';
std::cout << szString << std::endl;
-
May 16th, 2002, 10:14 AM
#5
Thread Starter
Addicted Member
Oki i found it myself (took me a few hours, lol)
szString = strtok (szString,"\n");
that's what i needed , thnx anyway
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|