|
-
Jan 5th, 2001, 04:28 PM
#1
Thread Starter
Frenzied Member
Hi,
I've read through some examples that show how to concatenate strings but can't seem to get any of them to work in a Win32 app.
What I would like to do is the following:
char* val1;
char* val2;
MessageBox(hDlg,val1 + " " + val2,"Info",MB_OK);
Now I know that wont work as it is but I just wanted to make it clear what I wanted to do..
I'm not using MFC.
Any help and examples would be greatly appreciated..
Dan
-
Jan 5th, 2001, 05:25 PM
#2
Frenzied Member
You could use the
lstrcat api:
Code:
MessageBox(hDlg,lstrcat(val1, val2),"Info",MB_OK);
But if you include string you could also concatenate using the + you provided.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 5th, 2001, 06:11 PM
#3
Code:
#include <string.h>
.
.
.
char buffer1[] = "Hello";
char buffer2[] = "You";
strcat(buffer1, ", ");
strcat(buffer1, buffer2);
cout<<buffer1<<endl;
-
Jan 5th, 2001, 06:17 PM
#4
Monday Morning Lunatic
Code:
#include <string>
using std::string;
...
char *one = "Hello";
char *two = "World";
MessageBox(NULL, string(one) + " " + two, "Message", MB_OK);
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 5th, 2001, 06:35 PM
#5
Frenzied Member
He already uses the MessageBox API call, so he probably already has
#include windows.h
so why not use the
lstrcat from the windows.h?
Saves you one header file
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 5th, 2001, 06:39 PM
#6
Monday Morning Lunatic
You have to be careful not to get inconsistencies between the way all the arrays are allocated. For example, there are 3 ways just off the top of my head:
new / delete / delete[] (c++)
malloc / free (c)
GlobalAlloc / GlobalFree (windows)
The strcat functions automatically extend the char* array - so if it uses a different allocation method to the one you originally used to make the string, then you'll get a GPF
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 5th, 2001, 06:43 PM
#7
Thread Starter
Frenzied Member
Thanks guys! ChimpFace9000's code works but I can't seem to get Jop's code to work.. On Jop's, it doesn't error out but it just doesn't show the MessageBox when I put the lstrcat(val1,val2) in there.. Oh well.. I would've liked to use that cause it's a lot cleaner..
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
|