Shiva
Shiva

Reputation: 165

Efficient method to store int as string in c

I have an integer int ThermoTemp=55 I need to convert it as string and store in char Thermoprint[6]

i just want it as 05.5,

here is the code i have tried

 ThermoPrint[0]=((ThermoTemperature/100)+0x30);
 ThermoPrint[1]=(((ThermoTemperature/10)%10)+0x30);
 ThermoPrint[3]=((ThermoTemperature%10)+0x30);
 ThermoPrint[2]='.';
 ThermoPrint[4]=',';

is there any efficient method to do this?

Upvotes: 0

Views: 119

Answers (1)

sukhvir
sukhvir

Reputation: 5575

Here is one way:

  sprintf(Thermoprint,"%02d.%d",ThermoTemp/10,ThermoTemp%10);

(thanks for the suggestion squeemish )

Upvotes: 4

Related Questions