Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to format output control length in C language

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how the C language formats the output control length, the content is detailed and easy to understand, the operation is simple and fast, and it has certain reference value. I believe you will gain something after reading this article on how to format the output control length in C language. let's take a look.

C language format output control length

When you implement the ls command, the output filename is aligned up and down:

12 a.c b crawler text public video documentation music 1.c 2.c a.out b.c git win template picture download desktop

I want to achieve alignment and think of the formatted output of c

Printf ("%-10s", s)

In this way, the string s occupies 10 squares and is output to the left.

However, due to a problem that is difficult to solve, the above 10 cannot be advanced and is calculated while the program is running, so I wonder if it can be output like this:

Int axi5tchar s [] = "hell"; printf ("% -% ds", Amens)

If it turns out that this will not work, we must think of other solutions.

Then look at the format of printf, printf's format control is in "", whether it means that you can replace "" with a string, and then try:

Char a [] = "s"; char s [] = "hello"; printf (amens)

Successful output:

Hello

It seems that this is feasible, so the code is written:

Int nymphs 13; char na [3]; if (n > 9) {na [0] = (Number10) + 48; na [1] = (n) + 48; na [2] ='\ 013;} else {na [0] = n + 48; na [1] ='\ 013;} char a [10] = "% -"; strcat (aQuinna); char s [] = "s"; strcat (amens) Char b [] = "hellow"; puts (a); printf (a)

N is the maximum length of the filename output by ls (visual should not be greater than 99).

This is the end of the article on "how to format output control length in C language". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to format the output control length in C language". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report