2012-09-15 134 views
0

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

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

输出想

" Four spaces before the sentence gets printed" 

回答

1

%s格式说明可以采取宽度int值:

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

打印

Test