提问人:user22712878 提问时间:11/15/2023 更新时间:11/15/2023 访问量:49
在 C 语言中对齐 printf 语句
Aligning printf statements in C
问:
我有一些价值观想向左对齐。但是,两个数字 2400 和 2500 有额外的偏移量,我假设这是因为导致它的 key.name 更长。我能做些什么来正确对齐这些值?我是否缺少其他对齐方法?
我的代码
void print_key(Key key) {
char c = ' ';
printf("%-5d%-15s%-40c",key.num, key.name,c);
}
// Input: ’node’: a node
// Effect: node.key is printed and then the node.data is printed
void print_node(Node node) {
print_key(node.key);
printf("%d\n", node.data);
}
答: 暂无答案
评论
15s
25s
Beechmount Crescent
printf("%-5d%-55s",key.num, key.name);