資源簡介
嵌入式開發時經常要用到字符串轉換函數sprintf,但標準C函數庫非常占內存,重寫更高效更精簡的sprintf函數,比C標準庫里自帶的sprintf更高效,適用于嵌入式或上位軟件開發。
代碼片段和文件信息
#include?
static?void?t_printchar(char?**str?int?c)
{
extern?int?putchar(int?c);
if?(str)?{
**str?=?c;
++(*str);
}
else?(void)putchar(c);
}
#define?PAD_RIGHT?1
#define?PAD_ZERO?2
static?int?t_prints(char?**out?const?char?*string?int?width?int?pad)
{
register?int?pc?=?0?padchar?=?‘?‘;
if?(width?>?0)?{
register?int?len?=?0;
register?const?char?*ptr;
for?(ptr?=?string;?*ptr;?++ptr)?++len;
if?(len?>=?width)?width?=?0;
else?width?-=?len;
if?(pad?&?PAD_ZERO)?padchar?=?‘0‘;
}
if?(!(pad?&?PAD_RIGHT))?{
for?(?;?width?>?0;?--width)?{
t_printchar?(out?padchar);
++pc;
}
}
for?(?;?*string?;?++string)?{
t_printchar?(out?*string);
++pc;
}
for?(?;?width?>?0;?--width)?{
t_printchar?(out?padchar);
+
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3753??2012-07-11?13:02??t_sprintf.c
-----------?---------??----------?-----??----
?????????????????3753????????????????????1
評論
共有 條評論