C Code Formatter & Beautifier

Use the formatter to review compact C snippets. It applies general C-style layout rules, not compiler validation; check the output with your toolchain.

Runs locally in your browser

How to reformat C source in the editor

Paste a C file or snippet into the editor and press the format button: the tool re-breaks the lines after braces and semicolons, indents the result with tabs and renders it highlighted in the panel below.

It is a text-level layout pass, not a compiler. String literals, comments and preprocessor lines pass through untouched, and the editor keeps your original text so you can compare the two.

  1. Paste or type C source into the editor; the default example is a minimal program you can overwrite.
  2. Press C Language Code Formatting. The result appears in the highlighted panel underneath.
  3. If you change the input afterwards, the old result dims and a notice asks you to run the formatter again, so a stale layout is never presented as current.
  4. Copy takes the formatted text from the panel; Clear empties the editor and the result.
  5. For very large outputs the panel drops the syntax colours and shows plain text to keep the page responsive.

What the formatter rewrites, and what it leaves alone

What is preserved verbatim

Measured on the page: char *p="a;b}"; keeps the semicolon and the closing brace inside the string, the comment /* block ; { } */ keeps its punctuation, and a macro with backslash continuations (#define LONG(a) do { \ ...) comes back character for character, including #define X {1,2} on a single line.

That is the point of the tool: only whitespace moves. When a snippet depends on exact spacing inside macros or on continuation lines, the formatter leaves those lines alone rather than risk changing the program.

Where the layout stays approximate

The pass is driven by text scanning, not by a grammar, so compact one-liners are expanded by rules. struct S{int a;char *b;};typedef struct S S; becomes four lines, but the trailing };typedef struct S S; stays on one line: expressions are not re-spaced.

Nothing is compiled, parsed or validated. A missing semicolon, unbalanced braces or invalid syntax produce a best-effort layout instead of an error message, so treat the output as a readable draft and run it through your compiler or linter afterwards.

Large files

Formatting runs entirely inside the page. A 64 KB sample (4,000 statements, about 82 KB of output) returns in under a second in Chrome, and the run issues no network requests at all, so it needs no connection.

Above roughly 120,000 characters of output the panel switches to plain text without colours, which keeps long files from stalling the tab. For files that size, splitting the input or using a local formatter is still the more comfortable workflow.

Recent tools: