vsnprintf的使用--构建自己的格式化打印函数

#if 0
stdio.h中,v开头的print函数和scan函数,都是支持__va_list 参数的,也就是...转换后的参数列表结构;
可以用来封装自己的格式化打印函数
extern _ARMABI int vsprintf(char * __restrict /*s*/,
                     const char * __restrict /*format*/, __va_list /*arg*/) __attribute__((__nonnull__(1,2)));
   /*
    * is equivalent to sprintf, with the variable argument list replaced by
    * arg, which has been initialised by the va_start macro (and possibly
    * subsequent va_arg calls). The vsprintf function does not invoke the
    * va_end function.
    * Returns: the number of characters written in the array, not counting the
    *          terminating null character.
    */

extern _ARMABI int vsnprintf(char * __restrict /*s*/, size_t /*n*/,
                     const char * __restrict /*format*/, __va_list /*arg*/) __attribute__((__nonnull__(3)));
   /*
    * is equivalent to snprintf, with the variable argument list replaced by
    * arg, which has been initialised by the va_start macro (and possibly
    * subsequent va_arg calls). The vsprintf function does not invoke the
    * va_end function.
    * Returns: the number of characters that would have been written in the
    *          array, not counting the terminating null character. As
    *          snprintf.
    */
#endif

int LCD_LinePrint(int rows,const char *format, ... )
{
	char buff[65]={0};
	uint8_t columns=0;
	va_list arg;
	int done;
	//LCD_WriteInstructions(CMD_RETURN_HOME);
	va_start (arg, format);
	done = vsnprintf(buff,sizeof(buff),format,arg);
	va_end (arg);

	done = done>LCD_CHAR_BUFFER_MAX?LCD_CHAR_BUFFER_MAX:done;
	rows = rows%LCD_LINE_MAX;

	for (columns=0;columns<done;columns++){
		LCD_PutChar(rows,columns,buff[columns]);
	}

	return done;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值