Use ident to format your C program

Source: Internet
Author: User

This site mentioned the Linux tool indent and tried it for a while. It is really easy to use. To sum up, I hope it will help readers.

 

 Download and install:

1. For Linux (Fedora) users, the simplest installation method is "yum install indent"

2. Windows
You can download the package from http://gnuwin32.sourceforge.net/packages/indent.htm.

 

Usage:

For more information, see http://www.worldhello.net/doc/program_rules/indent.html.

I tried it several times and found that the parameter "-I4-bli0-ut-ts4" is my favorite style.

 

How to format files in batches (my own script has been verified)

1. Windows users:

1. Enter the source code root directory you need To Format

2. Save the following content as indent_my_prg.bat

3. Run indent_my_prg.bat

 

@ Echo off

Setlocal enabledelayedexpansion

Dir *. C/S/B> c_list.txt

For/F "tokens = 1 * delims =" % A in ('findstr. c_list.txt ') Do (

: Echo %

Set AA = %

Indent-I4-bli0-ut-ts4! Aa !)

 

1. Linux users:

1. Enter the source code root directory you need To Format

2. Save the content under ------- as indent_my_prg_in.sh.

3. Run indent_my_prg_in.sh.

 

@ Echo off

Setlocal enabledelayedexpansion

Dir *. C/S/B> c_list.txt

For/F "tokens = 1 * delims =" % A in ('findstr. c_list.txt ') Do (

: Echo %

Set AA = %

Indent-I4-bli0-ut-ts4! Aa !)

 

What kind of code can indent arrange? The following is an example. The following shows a program that can calculate the factorial of A large number due to abnormal formats.

 

# Define n 100

Int A [n * 5] = {1}, n = N, I, C, M = 1; Main () {for (; n --) {for (C = I = 0; I <M | C;) A [I ++] = (C + = A [I] * n) % 10, c/= 10; M = I;} For (; m;) putch (A [-- m] + 48 );}

 

Below is the code after the format is rearranged. Isn't it nice.

 

#define N 100
int a[N * 5] = { 1 }, n = N, i, c, m = 1;
main ()
{
        for (; n; n--)
        {
                  for (c = i = 0; i < m || c;)
                           a[i++] = (c += a[i] * n) % 10, c /= 10;
                  m = i;
        }
        for (; m;)
                  putch (a[--m] + 48);
}

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: info-contact@alibabacloud.com 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.