Arduino sprintf函数的用法详解
:
sprintf()
:把格式化的数据写入某个字符串缓冲区。
来自:stdio.h
原型
int sprintf( char *buffer, const char *format, [ argument] … );
参数列表
buffer:char型指针,指向将要写入的字符串的缓冲区。
format:格式化字符串。
[argument]…:可选参数,可以是任何类型的数据。
返回值:字符串长度(strlen
)相当于length()
函数
void setup()
{
Serial.begin(9600);
char logString[130];
int totalDay =2;
int totalMonth=2;
int totalYear=2013;
int totalHour=8;
int totalMinute=5;
sprintf(logString,"%02d.%02d.%4d,%02d:%02d,",totalDay,totalMonth,totalYear,totalHour,totalMinute);
Serial.println(logString);
}
void loop(){}