用sprintf填充 [英] padding with sprintf

查看:110
本文介绍了用sprintf填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个假的问题。我想将一个整数打印到一个填充为0的缓冲区中,但是我无法将其排序为 sprintf 格式。
我正在尝试以下操作

I have a dummy question. I would like to print an integer into a buffer padding with 0 but I cannot sort it out the sprintfformat. I am trying the following

char buf[31];
int my_val = 324;
sprintf( buf, "%d030", my_val );

希望具有以下字符串

"000000000000000000000000000324"

我在做什么错?这不是说以0填充最大宽度为30个字符?

what am I doing wrong? It doesn't mean pad with 0 for a max width of 30 chars?

推荐答案

%030d 是您要查找的机器人

这篇关于用sprintf填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆