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);
}