Forrest logo
back to the indent tool

indent:tldr:812b2

indent: Format C/C++ source according to the style of Kernighan & Ritchie (K&R), no tabs, 3 spaces per indent, and wrap lines at 120 characters.
$ indent --k-and-r-style --indent-level3 --no-tabs --line-length120 ${path-to-source-c} -o ${path-to-indented_source-c}
try on your machine

The provided command:

indent --k-and-r-style --indent-level3 --no-tabs --line-length120 ${path-to-source-c} -o ${path-to-indented_source-c}

is using the indent command-line utility to format a C source code file according to specific style and indentation preferences.

Let's break down the command and its options:

  • indent: It is the name of the command to be executed. In this case, it refers to the indent utility.
  • --k-and-r-style: This option specifies that the code should be formatted using the K&R (Kernighan and Ritchie) coding style. K&R style includes placing opening braces on the same line as the corresponding control statement and using a specific indentation format.
  • --indent-level3: This option sets the indentation level to 3 spaces. It means each level of indentation will be 3 spaces.
  • --no-tabs: This option instructs indent not to use tabs for indentation, rather use spaces only.
  • --line-length120: This option sets the maximum line length to 120 characters. If a line exceeds this limit, indent will break it into multiple lines.
  • ${path-to-source-c}: This placeholder indicates the path to the source C file that you want to format. Replace ${path-to-source-c} with the actual path to your C file.
  • -o ${path-to-indented_source-c}: This option followed by a path specifies the output file for the indented source code. Replace ${path-to-indented_source-c} with the desired path for the formatted C file.

By combining these options, the indent utility will parse and reformat the C source code contained within the specified input file using the provided style, indentation, and other preferences. The formatted code will then be saved to the specified output file.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the indent tool