C language > Beginner questions

how can i get an int to a messagebox

(1/1)

elektrik1000:
thanks for the nice compiller I am newbee;
I have a problem I wants to get an int to a messagebox but i only get acsii carakter how can i get the data from an int to the messagebox.


int hey = 55;
MessageBox(hwnd, hey, "This program is:", MB_OK | MB_ICONINFORMATION);

Building frabeg.obj.
C:\Program Files\PellesC\Projects\frabeg\frabeg.c(35): error #2140: Type error in argument 2 to a function; found 'int' expected 'const char *'.
*** Error code: 1 ***
Done.

sorry it's a simple thing but i am totally new in programming hopeing for understanding.... ???

thanx from dennis

Stefan Pendl:
Use sprintf to get char* from the int.

--- Code: ---char buffer[10];
int hey = 55;

sprintf(buffer, "%d", hey);
MessageBox(hwnd, buffer, "This program is:", MB_OK | MB_ICONINFORMATION);
--- End code ---

skirby:
Hello elektrik1000,

You simply have to convert you number to char.


--- Code: ---#include <windows.h>
#include <stdio.h>

int main(void) {
  int key;
  char s[10];
 
  // You can do it like this
  key = 55;
  _itoa(key, s, 10);
  MessageBox(0, s, "Convert Int to Char", MB_ICONINFORMATION);

  // Or like that
  key = 212;
  wsprintf(s, "%d", key);
  MessageBox(0, s, "Convert Int to Char", MB_ICONINFORMATION);

  return 0;
}
--- End code ---

Navigation

[0] Message Index

Go to full version