Results 1 to 5 of 5

Thread: Convert double to Char/

  1. #1

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Convert double to Char/

    Hello, I'm trying to convert a double to a char. how to acomplish that?
    Code:
    double t=sqrt(10)
    MessageBox(NULL,t,"",0);
    Always gives me an error, cannot convert double to char. Please give advice on how to solve this. Also, when I'm trying to use strcpy and strcat
    Code:
    double t=sqrt(10)
    char T[MAX_LENGTH];
    strcpy(T,"Hello this number is: ");
    strcat(T,t);
    Won't work. How to solve this as well? Thanks.

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Code:
    #include <stdio.h>
    
    //...
    double t=sqrt(10)
    char T[MAX_LENGTH];
    
    sprintf(T,"%d", t)
    
    //...
    try that.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post What happen?

    Code:
    #include <windows.h>
    #include "resource.h"
    #define MAX 256
    #define TIMER_10SEC 1
    HWND dlg;
    BOOL CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
    double x=LOWORD(lParam),y=HIWORD(lParam);
    SetTimer(hwnd,TIMER_10SEC,1000,NULL);
    	switch(msg){
    	case WM_INITDIALOG:
    		MessageBox(hwnd,"'Look, I can be the meanest son of a ***** in this school!'","Mr. Olds says",MB_ICONEXCLAMATION|0);
    		break;
    	case WM_CLOSE:
    		DestroyWindow(hwnd);
    		PostQuitMessage(0);
    		break;
    			case WM_KEYDOWN:
    		switch(wParam){
    		case VK_ESCAPE:
    			SendMessage(hwnd,WM_CLOSE,0,0);
    			break;
    		case VK_F1:
    			MessageBox(NULL,"hey","",0);
    
    			break;
    		}	
    		case WM_TIMER:
    			switch(wParam){
    			case TIMER_10SEC:
    				MessageBox(NULL,"Ms. Van Norton Suk!","...",MB_ICONEXCLAMATION|0);
    				break;
    			}
    			break;
    	default:
    		return 0;
    	}
    return TRUE;
    }
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd){
    	MSG msg;
    	dlg=CreateDialog(hInstance,MAKEINTRESOURCE(main_prog),NULL,WndProc);
    	if(dlg==NULL){
    		MessageBox(NULL,"Cannot create Windows, please recheck your system","From TZ",MB_ICONEXCLAMATION|0);
    		return 0;
    	}
    		ShowWindow(dlg,nShowCmd);
    		
    
    
    
    
    
    
    			while(GetMessage(&msg,NULL,NULL,NULL)){
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    		return msg.wParam;
    
    }
    I want the Timer to be occured on the MAIN WINDOW, not the MessageBox. How?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  4. #4

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post sprintf();

    Hello, every experts, I would like to know how to do this:
    Code:
    double Y=sqrt(10);
    char X[MAX_LENGTH];
    sprint(X,"%d",Y);
    MessageBox(NULL,X,"",0);
    When the messagebox pop up, it's something not sqrt of 10, and when I change 10 to 100, it gave me 0. What happened?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use %f rather than %d.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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