2012-09-15 5 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