iCAx开思网
标题:
double型怎样转换成char型附源码
[打印本页]
作者:
haidong2008
时间:
2009-12-25 12:00
标题:
double型怎样转换成char型附源码
//////////////////////////////////////////////////////////////////////////////
//
// 5.cpp
//
// Description:
// Contains Unigraphics entry points for the application.
//
//////////////////////////////////////////////////////////////////////////////
// Include files
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <uf.h>
#include <uf_disp.h>
#include <uf_modl.h>
#include <uf_ui.h>
#include <uf_object_types.h>
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
# include <strstream>
# include <iostream>
using std:
strstream;
using std::endl;
using std::ends;
using std::cerr;
#else
# include <strstream.h>
# include <iostream.h>
#endif
#include "6.h"
//----------------------------------------------------------------------------
// Activation Methods
//----------------------------------------------------------------------------
// Unigraphics Startup
// This entry point activates the application at Unigraphics startup
extern "C" DllExport void ufsta( char *param, int *returnCode, int rlen )
{
/* Initialize the API environment */
int errorCode = UF_initialize();
if ( 0 == errorCode )
{
tag_t block_max;
double block_orig[3]={0.0,0.0,0.0};
double x=100.0,y=100.0,z=100.0;
char
mx
[256];
char
my
[256];
char
mz
[256];
char * block_len[3];
sprintf(
mx
,"x的边长是:%f\n",x);
sprintf(
my
,"y的边长是:%f\n",y);
sprintf(
mz
,"x的边长是:%f\n",z);
UF_UI_open_listing_window();
UF_UI_write_listing_window(mx);
UF_UI_write_listing_window(my);
UF_UI_write_listing_window(mz);
block_len[0]=mx;
block_len[1]=my;
block_len[2]=mz;
UF_FEATURE_SIGN sign=UF_NULLSIGN;
UF_MODL_create_block1(sign,block_orig,
block_len
,&block_max);
errorCode = UF_terminate();
}
/* Print out any error messages */
PrintErrorMessage( errorCode );
}
//----------------------------------------------------------------------------
// Utilities
//----------------------------------------------------------------------------
// Unload Handler
// This function specifies when to unload your application from Unigraphics.
// If your application registers a callback (from a MenuScript item or a
// User Defined Object for example), this function MUST return
// "UF_UNLOAD_UG_TERMINATE".
extern "C" int ufusr_ask_unload( void )
{
return( UF_UNLOAD_UG_TERMINATE );
}
/* PrintErrorMessage
**
** Prints error messages to standard error and the Unigraphics status
** line. */
static void PrintErrorMessage( int errorCode )
{
if ( 0 != errorCode )
{
/* Retrieve the associated error message */
char message[133];
UF_get_fail_message( errorCode, message );
/* Print out the message */
UF_UI_set_status( message );
// Construct a buffer to hold the text.
ostrstream error_message;
// Initialize the buffer with the required text.
error_message << endl
<< "Error:" << endl
<< message
<< endl << endl << ends;
// Write the message to standard error
cerr << error_message.str();
}
}
作者:
look_tfq
时间:
2009-12-25 13:03
用sprintf命令
作者:
look_tfq
时间:
2009-12-25 13:06
char tempStr[133]="";
double a=150.30;
sprintf(tempStr,"%.3f",a);
我一般这样转换的
作者:
look_tfq
时间:
2009-12-25 13:06
char tempStr[133]="";
double a=150.30;
sprintf(tempStr,"%.3f",a);
我一般这样转换的
作者:
haidong2008
时间:
2009-12-25 13:17
谢谢,我先试一下了。
作者:
haidong2008
时间:
2009-12-25 13:25
我试一了下,还是不行,生成不了BLOCK.。老大能帮我改一下代码么,谢谢了!
作者:
haidong2008
时间:
2009-12-25 13:46
终于搞定了!
欢迎光临 iCAx开思网 (https://www.icax.org/)
Powered by Discuz! X3.3