Anfängerfrage: Richtige Ausgabe von Variablen in String
-
Hi,
Ich bin nun etwas weiter und habe einen Quellcode, der läuft und mir wird per printf die Werte richtig ausgegeben. Mein Problem ist nun recht simpel. Ich brauche dafür einen Mysql String, um das in die Datenbank zu packen.
string sql; switch( UartData.GetTempData() ) { case 2: UartData.GetTempData(); sql ="INSERT INTO `Counter`.`223` (`timestamp`, `RL`, `VL`, `RL2`, `VL2`, `WW`, `KK`, `Power`, `VOL1`, `VOL2`) VALUES (CURRENT_TIMESTAMP, '"; sql +=UartData.m_ThermData.t.RL; sql += "','"; sql +=UartData.m_ThermData.t.VL; sql += "','"; sql +=UartData.m_ThermData.t.RL2; sql += "','"; sql +=UartData.m_ThermData.t.VL2; sql += "','"; sql +=UartData.m_ThermData.t.WW; sql += "','"; sql +=UartData.m_ThermData.t.KK; sql += "','0','0','0');"; printf(sql.c_str()); printf( "%.3f,%02X,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f", UartData.m_ThermData.t.timestamp/1000.0, UartData.m_ThermData.t.bits, UartData.m_ThermData.t.RL2/10.0, UartData.m_ThermData.t.VL/10.0, UartData.m_ThermData.t.VL2/10.0, UartData.m_ThermData.t.RL/10.0, UartData.m_ThermData.t.WW/10.0, UartData.m_ThermData.t.KK/10.0, UartData.m_ThermData.t.dRL/100.0, UartData.m_ThermData.t.B20/100.0 ); busy = false; break; } break;
class CY_UartData : public CY_Device { public: enum E_Buf { ePlot, ePower, eThermBuf, eCal, eThermState, eFlash, eBufSize }; CY_UartData ( const uchar p_ID ); ~CY_UartData ( void ); void Init ( void ); bool PortSelect ( std::string & p_Port ); bool SetBaudRate ( ulong p_Baud ); void InitSeq ( void ) { m_Seq = 0; }; bool GetUartData ( uchar * p_pBuf, uchar p_Size, E_Buf p_Dest, bool p_Sort = true ); void WriteUartFrame( uchar * p_pData, uchar p_Size ); void Clear ( void ); T_CBUF * GetBuf ( uchar p_ID ); uchar GetTempState ( void ); uchar GetTempData ( void ); uchar GetPowerData ( void ); uchar GetThermalBuf ( void ); uchar SetCalChannel ( uchar p_Ch ); uchar GetCalData ( void ); uchar Bootload ( uchar p_ID ); uchar FlashVerify ( T_DeviceCfg& p_Cfg ); uchar FlashWrite ( T_DeviceCfg& p_Cfg ); uchar Calibrate ( T_DeviceCfg& p_Cfg ); uchar FlashReset ( uchar p_ID ); uchar SendCommand ( uchar p_Dest, uchar p_Cmd ); T_CBUF m_DataBuf[eBufSize]; ushort m_Counter; ushort m_ReceiveCnt; ushort m_TimeoutCnt; static ushort s_AdrStart; static ushort s_AdrEnd; static ushort s_Adr; U_ThermData m_ThermData; uchar m_dv; uchar m_dr; uchar m_CalChannel; char m_Delta[256]; uchar m_DeltaCnt[128]; protected: uchar m_Seq; ulong m_Baudrate; uchar m_DataBufArray[eBufSize][0xFF]; CY_MyFrame * m_pFrame; static uchar s_Trials; static ushort s_TimeRef; static uchar s_FileFlashData[128*1024]; }; extern CY_UartData UartData;
Vielleicht hat ja jemand einen Tipp, wie ich das anpacken kann?
Gruß kami
-
sprintf()
?
-
Hab ich schon probiert. Klappt aber nicht ganz. Wie müsste sowas aussehen. Bin totaler Anfänger.
Danke.
Gruß kami
-
-
char charArray[1000]; ... sprintf(charArray, "%.3f,%02X,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f",...
-
Hi,
klappt super.
Vielen Dank.
Gruß kami