How to beautify the code in a C file


I’ve tried using Ctrl+Shift+B and I get Error message: “This code could not be beautified “c_cpp” is not supported yet”

Is there any other option for auto-indentation?
When will your team begin to support c / cpp also?

Thanks a lot, Matan.


If you’re not afraid of the command line, the “classic” program for indenting C is indent. It’s not quite as good at C++ but it’s worth a try! You may want to make a backup copy in case you don’t like what it does. It’s pre-installed on a custom installation of C9, and you can run it from the terminal window (near the bottom of a typical C9 screen).

You pop into the terminal, cd to the directory your C++ source is in, and then do

indent yourSource.cpp

I like to use

indent -kr -nut -i3 mySource.cpp

to get “Kernighan & Ritchie” style, spaces instead of tabs, and an indent width of 3.

man indent

gives you the whole manual, which is not exactly a friendly read unfortunately.

clang-format is said to be better for C++. It’s not pre-installed but you can install it by typing, again in the terminal,

sudo apt-get install clang-format-3.6

There’s probably a man page for that as well. I’m sorry I don’t have experience to share with this program.