NO

Author Topic: how can i get an int to a messagebox  (Read 3942 times)

elektrik1000

  • Guest
how can i get an int to a messagebox
« on: June 21, 2007, 10:14:23 PM »
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


Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: how can i get an int to a messagebox
« Reply #1 on: June 22, 2007, 12:02:59 AM »
Use sprintf to get char* from the int.
Code: [Select]
char buffer[10];
int hey = 55;

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

Proud member of the UltraDefrag Development Team

skirby

  • Guest
Re: how can i get an int to a messagebox
« Reply #2 on: June 22, 2007, 12:04:18 AM »
Hello elektrik1000,

You simply have to convert you number to char.

Code: [Select]
#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;
}