|
-
Jan 17th, 2006, 07:52 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] how do i concat stuff in c++?
in vb we use & , e.g.
variable & "whatever"
what about C?
-
Jan 17th, 2006, 08:00 PM
#2
Hyperactive Member
Re: how do i concat stuff in c++?
-
Jan 17th, 2006, 08:02 PM
#3
Thread Starter
Frenzied Member
Re: how do i concat stuff in c++?
ok, but this gives me an error saying cann't add 2 pointers
Code:
extern "C" int WINAPI Test(HWND, HWND, char *data, char *parms, BOOL, BOOL) {
_fstrcpy(data, data + "hi");
return 3;
}
-
Jan 17th, 2006, 08:03 PM
#4
Hyperactive Member
Re: how do i concat stuff in c++?
Yeah I know I wasn't thinking when I posted. I'm half asleep. College killed me today. Let me look. Sorry.
Well in that code, the data variable is a pointer. Not sure if your familiar with those but that a memory address, not a value. You can't add two memory address together but you can add their contents using the indirection operator.
Last edited by GamerMax5; Jan 17th, 2006 at 08:07 PM.
-
Jan 17th, 2006, 08:07 PM
#5
Thread Starter
Frenzied Member
Re: how do i concat stuff in c++?
thanks for you help and replies mate,
"you can add their contents using the indirection operator"
whats the indirection operator?
-
Jan 17th, 2006, 08:09 PM
#6
Hyperactive Member
Re: how do i concat stuff in c++?
The asterisk before the word data is the indirection operator. It tells the compiler that you're wanting to access a memory address. Let me know if you don't know how to add the contents and I'll show you.
-
Jan 17th, 2006, 08:12 PM
#7
Thread Starter
Frenzied Member
Re: how do i concat stuff in c++?
ok thanks i just did this
_fstrcpy(data, *data + "hi");
and it returned something weird
a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
edit -----------
Im calling the function from my mIRC application, it all works fine when its like this
_fstrcpy(data, data);
so if i do //echo -a $dll(Test.dll, Test, Hello) in mIRC, it echos the word Hello.
Now changing it to _fstrcpy(data, *data + "hi");
i want it to echo the paramtered word with 'hi' appended on the end so
//echo -a $dll(Test.dll, Test, Hello) would be Hellohi
Last edited by Pouncer; Jan 17th, 2006 at 08:16 PM.
-
Jan 17th, 2006, 08:19 PM
#8
Hyperactive Member
Re: how do i concat stuff in c++?
lol If that works then just put a space in before the word "hi" and then it should work.
//echo -a $dll(Test.dll, Test, Hello)
If this line works, then try concatenating after the word "Hello"
-
Jan 17th, 2006, 08:22 PM
#9
Thread Starter
Frenzied Member
Re: how do i concat stuff in c++?
what you mean lol
like this?
_fstrcpy(data, *data + " hi");
-
Jan 17th, 2006, 08:24 PM
#10
Thread Starter
Frenzied Member
Re: how do i concat stuff in c++?
 Originally Posted by GamerMax5
lol If that works then just put a space in before the word "hi" and then it should work.
If this line works, then try concatenating after the word "Hello"
yeah that works but im trying to do it through c++ for testing purposes
-
Jan 17th, 2006, 08:24 PM
#11
Hyperactive Member
Re: how do i concat stuff in c++?
lol Try it and if it works then run with it.
-
Jan 17th, 2006, 08:26 PM
#12
Thread Starter
Frenzied Member
Re: how do i concat stuff in c++?
Code:
extern "C" int WINAPI Test(HWND, HWND, char *data, char *parms, BOOL, BOOL) {
_fstrcpy(data, *data + " hi");
return 3;
}
when i do //echo -a $dll(Test.dll, Test, hello) it should echo
Hellohi
but it echos
a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
LOL, odd
-
Jan 17th, 2006, 08:27 PM
#13
Hyperactive Member
-
Jan 17th, 2006, 08:29 PM
#14
Thread Starter
Frenzied Member
Re: how do i concat stuff in c++?
no problem mate, thanks for all your help,
lets hope someone else might have a clue on this!
-
Jan 17th, 2006, 08:39 PM
#15
Re: how do i concat stuff in c++?
In C++, you should use the std::string class. The + operator is overloaded to allow you to add string literals as well as std::strings.
Code:
#include <string>
#include <iostream>
using namespace std;
// ...
string a = "hello";
string b = " there";
string result = a + b + " everyone";
In C using character pointers (as in your first post) you can use sprintf() or strcat.
Code:
char somestring[64] = "hello";
char other[] = " there";
char result[256];
strcat(somestring, other); // somestring now equals "hello there"
sprintf(result, "%s %s everyone", somestring, "there"); // result now equals "hello there everyone"
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Jan 17th, 2006, 08:42 PM
#16
Thread Starter
Frenzied Member
Re: how do i concat stuff in c++?
ah thanks!!!
_fstrcpy(data, strcat(data, "hi"));
works perfect!
-
Jan 17th, 2006, 08:46 PM
#17
Hyperactive Member
Re: [RESOLVED] how do i concat stuff in c++?
Wow.
Even though this wasn't my original post, I feel so much more relieved. lol
-
Jan 22nd, 2006, 06:12 PM
#18
Thread Starter
Frenzied Member
Re: [RESOLVED] how do i concat stuff in c++?
hey guys, when i do this
_fstrcpy(data, strcat(data, "hi")); it works fine
when i do this, it also works fine
lstrcpy(data, result); (with result being some data)
but with this i do this, i get error when i call the function from my mirc
lstrcpy(data, strcat("hi", result));
i want to concat "hi" to the beginning of the result, and put it into data to send back to mirc.. but it mIRC doesnt seem to like it, this works though
lstrcpy(data, strcat(result, "hi")); (but i want to concat "hi" at the begninning not the end)
*edit, i even tried lstrcpy(data, "hi" + result);
but that gives error saying it can't add 2 pointers
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
|