Jump to content
  • Advertisement
Sign in to follow this  
gretty

Combine 2 char arrays

This topic is 3046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I am trying to figure out how to combine 2 char arrays. I know I could easily combine 2 strings but I'm pretty sure I cant use strings for what I am trying to do. I am trying to convert 2 integers(x,y) to characters(char arrays) so I can display them in a static control(SetWindowText()). I can convert each x,y value to a char array but I dont know how to combine the 2 char arrays to send them to the static control to display psuedo code/function:

void displayPosition(HWND hwnd, UINT msg, POINT focusPnt)
{
  // Post: Displays the x,y coordinate where the mouse is in static control

  char x[MAX_PATH];
  char y[MAX_PATH];
  char pnt[MAX_PATH];
  itoa(focusPnt.x,x,10);
  itoa(focusPnt.y,y,10);

  // how can I combine x & y so I can display the result in the static control
  
  SendDlgItemMessage(hwnd,msg,WM_SETTEXT,0,(LPARAM)pnt);  // set control text
}

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by gretty
Hi

I am trying to figure out how to combine 2 char arrays. I know I could easily combine 2 strings but I'm pretty sure I cant use strings for what I am trying to do.

I am trying to convert 2 integers(x,y) to characters(char arrays) so I can display them in a static control(SetWindowText()). I can convert each x,y value to a char array but I dont know how to combine the 2 char arrays to send them to the static control to display

psuedo code/function:
*** Source Snippet Removed ***


Of course you can use strings for this [smile]

// don't forget
#include <sstream>

void displayPosition(HWND hwnd, UINT msg, POINT focusPnt)
{
// Post: Displays the x,y coordinate where the mouse is in static control

std::stringstream ss;
ss << focusPnt.x << ", " << focusPnt.y;
// ss now contains something like "4, 2" (no quotes of course)

// ss.str() gives us an std::string
// calling c_str() on that string gives us a null-terminated C-style string
SendDlgItemMessage(hwnd,msg,WM_SETTEXT,0,(LPARAM)ss.str().c_str()); // set control text
}




You just have to make sure SendDlgItemMessage() expects a null-terminated C-style string.

Share this post


Link to post
Share on other sites
(Assuming C)

sprintf

void displayPosition(HWND hwnd, UINT msg, POINT focusPnt)
{
// Post: Displays the x,y coordinate where the mouse is in static control
char buf[MAX_PATH];
sprintf( buf, "(%i, %i)", focusPnt.x, focusPnt.y );

SendDlgItemMessage(hwnd,msg,WM_SETTEXT,0,(LPARAM)buf); // set control text
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!