Results 1 to 18 of 18

Thread: [RESOLVED] how do i concat stuff in c++?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Resolved [RESOLVED] how do i concat stuff in c++?

    in vb we use & , e.g.

    variable & "whatever"

    what about C?

  2. #2
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Re: how do i concat stuff in c++?

    Not sure. lol

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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;
    }

  4. #4
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    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.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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?

  6. #6
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    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.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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.

  8. #8
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    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"

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: how do i concat stuff in c++?

    what you mean lol

    like this?

    _fstrcpy(data, *data + " hi");

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: how do i concat stuff in c++?

    Quote 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

  11. #11
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Re: how do i concat stuff in c++?

    lol Try it and if it works then run with it.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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

  13. #13
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Re: how do i concat stuff in c++?



    lol I think this is beyond my scope my friend. Sorry I couldn't be of more help.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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!

  15. #15
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    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.

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: how do i concat stuff in c++?

    ah thanks!!!

    _fstrcpy(data, strcat(data, "hi"));

    works perfect!

  17. #17
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    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

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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
  •  



Click Here to Expand Forum to Full Width