How to convert an INT to a CHAR for a CSV file?

Hi folks, I’m trying to make a data logger which will take the time and date from an RTC, measure a voltage, and then record all this data to an SD card.

I have working code for the reading the RTC, and working code for writing to the SD card.

My query is this… I want to write the date, time, and voltage to the SD card in CSV format. So, I need to set up a CHAR array with the date, time, and voltage all separated with commas. However, the date, time, and voltage are INTs. How do I convert the INTs to CHARs?

For example:
if the minutes from the RTC are 28, this needs to be converted to two ASCII characters, the ASCII character for the number 2, and the ASCII character for the number 8 so that the two characters can be written to the CHAR array.

Any help appreciated!

Thanks,

Andy.

itoa?

You can write your own function to do this too. Separate the digits then add '0' to each to get a char

.

sprintf() will allow you to format the whole string at once into your char array.

Why do you think you need to invent/use some function to convert an int to a string (NOT a CHAR)? Do you really believe that the File class can't do this?

Hi guys, thanks for all your replies.

evanmars, itoa worked a treat. Cheers!