Simply put, printf ("% * S % s", XX); or printf ("% * s \ n", XX, XX );

Source: Internet
Author: User

Do you still remember this example?

1 # include "public. H "2 3 int main () 4 {5 int A = 4; 6 printf (" % 4D \ n ", a); 7 return 0; 8}

The output result is:


There are three leading Spaces

Printf ("% * s",) is similar

"*" Indicates the number of locations

The first s represents a string.

The first parameter represents the number of digits, and the second parameter represents the string. The two parameters are combined to indicate the number of digits of the string. If not, use spaces on the left to complete the number of digits. maybe I am not talking too clearly. Let's use the code below to explain it.

1 # include <stdio. h> 2 3 int main () 4 {5 char * s = "12345"; 6 char Ss = 'a'; 7 printf ("% * s \ n", 10, s); 8 printf ("% * C \ n", 4, SS); 9}

### GCC text. c
###./A. Out

We can see that there are five spaces in front of 12345, plus 10 spaces in total in 12345, three spaces in front of a, and four spaces in total in front of.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.