Aritra Mukherjee Aritra Mukherjee - 3 months ago 29
C Question

How do I write a program to indent a C source code on a file?

I want to write it with c language....I was thinking of opening the file in append mode and run a loop with counter with every '{' opening braces...the loop will give '\t' (tab) for every opening brace and in the next opening brace the counter will increase i.e there will be 2 tabs like the idea correct? or will I have to do by a different method? I will do the program in devc++ IDE.


is it possible

  • yes, but not easy. There are lots of IDEs that try, and some do better than others.

comments are not taken into consideration

they have to be. Let's look at the code

void foo()
/** {this does something **/
{ baz(); }

you need to register that the { is in a comment, else you'll end up with everything with an extra tab, and a non-matching { at the end.