printf输出多列时的列对齐
来源:互联网 发布:香港银行开户 知乎 编辑:程序博客网 时间:2024/06/03 10:58
- 列左对齐
printf("%-*s", 20, string); 表示输出字符串左对齐输出20,如果字符串不够20个,以空格补齐。 -表示左对齐。
例:
struct help_struct
{
char *option_name;
char *option_value;
char *option_ext;
};
struct help_struct options[] =
{
{"set_node_id","node_id","set the node id"},
{"set_debug_level","debug_level","4:DEBUG 3:INFO 2:WARNING 1:ERR 0:NESS"},
{"flush_pool","pool_name",""},
{"get_lu_count","",""},
{"check_pools","pool_name",""},
{"invalid_pool","pool_name",""},
{"set_mirror","mirror_state","0:disable 1:enable"},
{(char*)NULL, (char*)NULL, (char*)NULL}
};
static void show_usage(const char *execname)
{
struct help_struct *opt = NULL;
printf("Usage: %s [options] ...\n", execname);
printf("Options:\n");
for(opt = options; opt->option_name; opt++)
{
printf(" --");
printf("%-*s",25, opt->option_name);
printf("%-*s",20, opt->option_value);
printf("%-*s",50, opt->option_ext);
printf("\n");
}
}
show_usage输出结果为:
Usage: ./vicm_test [options] ...
Options:
--set_node_id node_id set the node id
--set_debug_level debug_level 4:DEBUG 3:INFO 2:WARNING 1:ERR 0:NESS
--flush_pool pool_name
--get_lu_count
--check_pools pool_name
--invalid_pool pool_name
--set_mirror mirror_state 0:disable 1:enable
2. 右对齐
printf("%*s", 20, string); 表示输出字符串右对齐输出20,如果字符串不够20个,以空格补齐。 没有-表示右对齐。
例:
static void show_usage(const char *execname)
{
struct help_struct *opt = NULL;
printf("Usage: %s [options] ...\n", execname);
printf("Options:\n");
for(opt = options; opt->option_name; opt++)
{
printf(" --");
printf("%*s",25, opt->option_name);
printf("%*s",20, opt->option_value);
printf("%*s",50, opt->option_ext);
printf("\n");
}
}
show_usage输出结果为:
Usage: ./vicm_test [options] ...
Options:
-- set_node_id node_id set the node id
-- set_debug_level debug_level 4:DEBUG 3:INFO 2:WARNING 1:ERR 0:NESS
-- flush_pool pool_name
-- get_lu_count
-- check_pools pool_name
-- invalid_pool pool_name
-- set_mirror mirror_state 0:disable 1:enable
- printf输出多列时的列对齐
- printf输出多列时的列对齐
- <C语言>printf的对齐输出
- printf标准输出,右对齐
- shell脚本输出对齐问题(使用printf)
- printf 十六进制格式化输出 2字节对齐
- printf 十六进制格式化输出 2字节对齐
- C语言printf对齐输出方式
- printf可变输出列宽控制
- printf()的格式化输出
- printf的格式输出
- printf的输出顺序
- 关于printf的输出
- printf的格式化输出
- printf的异样输出
- printf的输出相关
- printf的输出规则
- printf的输出条件
- java.lang.NumberFormatException: multiple points特例及解决!
- Maya里面的模型动画导入Unity使用
- 去除复制代码的行号
- 在uboot中添加自己的命令
- QtXlsx在Windows x64下的编译配置及使用
- printf输出多列时的列对齐
- JavaEE学习08--jsp
- lightgbm python基本使用 --mac下操作
- sql之left join、right join、inner join的区别
- 云计算非功能性-可靠性可用性优化指标
- PAT 甲级 1016. Phone Bills
- select下拉框内容回显 并将对应的option设置为selected选中状态
- 使用MongoDB类操作MongoDB数据库总结
- (VS2010)MFC中List Control基本用法