RE: how to print out a floating value...

Tech-Archive recommends: Fix windows errors by optimizing your registry



Daniel,

I just built the following code with evc++ 4.0 and ran it successfully on a
CEPC. This is essentially what you are doing.

BT


// GCVTTest.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
char buffer[50];
double source = -3.1415e5;
_gcvt( source, 7, buffer );
printf( "source: %f buffer: '%s'\n", source, buffer );
_gcvt( source, 7, buffer );
printf( "source: %e buffer: '%s'\n", source, buffer );

return 0;
}

"daniel" wrote:

Hi?

I added the following codes which are from pb's help document to my bsp code.
But it seems the char, double type can't be available. there happens a
compile error.
error C2143: syntax error : missing ';' before 'type'
How can I solve this problem?

#include <stdlib.h>
#include <stdio.h>

....
char buffer[50];
double source = -3.1415e5;
_gcvt( source, 7, buffer );
printf( "source: %f buffer: '%s'\n", source, buffer );
_gcvt( source, 7, buffer );
printf( "source: %e buffer: '%s'\n", source, buffer );



"Bill T" wrote:

Another option is to use *_gcvt( double value, int digits, char* buffer );

BT

"daniel" wrote:

Hi?
I found a floating point value couldn't be printed out from ce os.
The following code is from
\PUBLIC\COMMON\OAK\DRIVERS\SDCARD\SDCLIENTDRIVERS\SDMEMORY\sdmemdiskio.cpp

DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemCalcDataAccessClocks: Tpd:%f ns,
Asynch: %f ns, AsyncClocks:%d , SyncClocks: %d, ReadTotal: %d, Write Factor:
%d WriteTotal: %d \n"),
clockPeriodNs,
....));

But the real print out message is like following @@

SDMemCalcDataAccessClocks: Tpd:f ns, Asynch: f ns, AsyncClocks:0 ,

You can see the value is not printed out but 'f' is printed instead!

What's wrong??
If I wanna print out some floating point value, how should I do?
.



Relevant Pages

  • RE: how to print out a floating value...
    ... But it seems the char, ... _gcvt(source, 7, buffer); ... I found a floating point value couldn't be printed out from ce os. ... But the real print out message is like following @@ ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Cannot return values of char variable
    ... - buffer = ... Since you seem to be trying to return a char pointer ... int id = random; ... content is interpreted as a string. ...
    (comp.lang.c)
  • Re: peer code review/advice needed for noob programmer
    ... And what is with the bizarre use of char **? ... Or using an obsolete data type like 'char'? ... to allocate a buffer here. ... BUt if you pass in a CString & String then the correct loop is ...
    (microsoft.public.vc.mfc)
  • Re: why I can not write to the file after initialize the MFC in a service program
    ... you don't use char, an obsolete data type ... Why do you need an intermedate buffer to write literal strings anyway? ... For example, if AfxWinInit fails, you copy a 45-character string into a ... So you are going to try to initialize MFC EACH TIME THROUGH THE LOOP? ...
    (microsoft.public.vc.mfc)
  • Re: why I can not write to the file after initialize the MFC in a service program
    ... you don't use char, an obsolete data type ... Why do you need an intermedate buffer to write literal strings anyway? ... For example, if AfxWinInit fails, you copy a 45-character string into a ... So you are going to try to initialize MFC EACH TIME THROUGH THE LOOP? ...
    (microsoft.public.vc.mfc)