Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert a float value into a char value

Status
Not open for further replies.

sirbu

Programmer
Sep 15, 1999
15
0
0
RO
I've written a code in C that performs several computations at various time steps. I want to save the results for each time step in a file. So if anybody can help me, how to change a float type number (the time value ex. 10.25) into a string so i can strcpy it into the file name.<br>ThankYou
 
I assume there is an ftoa command, just like there is an itoa, atoi, ltoa, atol commands. (in the standard libraries) <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
TCHAR&nbsp;&nbsp;&nbsp;cBuffer[128];<br><br>_stprintf(cBuffer,_T(&quot;%.4f&quot;), fValue);<br><br><br>where fValue is your time value, and cBuffer is the char pointer to pass to _tcscpy() (= Unicode-aware strcpy() ).<br><br>If you want to create the filename with the time in the same step:<br><br>TCHAR&nbsp;&nbsp;&nbsp;cFilename[128];<br><br>_stprintf(cFilename,_T(&quot;FILE%.4f&quot;), fValue);<br><br>You can alter the &quot;FILE&quot; part to whatever prefix you want for your filename.<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top