Pelles C forum

C language => Beginner questions => Topic started by: elektrik1000 on June 21, 2007, 10:14:23 PM

Title: how can i get an int to a messagebox
Post by: elektrik1000 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

Title: Re: how can i get an int to a messagebox
Post by: Stefan Pendl 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);
Title: Re: how can i get an int to a messagebox
Post by: skirby 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;
}