0

我想知道如何将 C printf 中的 print 语句格式化为在字母前有 4 个空格。其中空间位置由变量预先确定

int spaces = 4;
printf("Four spaces before the sentence gets printed")

输出想

"    Four spaces before the sentence gets printed"
4

1 回答 1

1

%s格式说明符可以将宽度作为int值:

printf("%*s%s", 2, "", "Test");

印刷

  Test
于 2012-09-15T14:59:03.253 回答