Thread: how to indent a file.

  1. #1
    Registered User
    Join Date
    Jan 2003

    how to indent a file.

    this is the program i have right now, this program reads the source file lab2.c and creates a new file called lab2b.c. what i wanna know is if the code in lab2.c is not indented properley how can i write a code to indent lab2.c properley.

    Help would be greatley appriciated, e-mail me if you have any questions!!!!!
    #include <stdio.h>
    int main()
        FILE *f,*ff;
        char s[100];
    	while (fgets(s,100,f)!=NULL)
        return 0;

    Code tags added by Hammer

  2. #2
    Registered User
    Join Date
    Dec 2002
    ::begin ominous voice

    You don't want to write this program. You want to search for some freeware that will beautify C/C++ code.

    ::end ominous voice
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    ::agrees with ominous voice

    This might be too much for you to tackle right now.

    However, as a longer-term project, I wouldn't discourage you! Make an outline of what your program needs to do (maybe a flow chart or psudo-code). Then as you learn, you can add features to your program.

    Basically, you need to load each line into a string, and then "parse" the string looking for things that should be indented, or be followed by an indent. You have to keep track of your indent-level, and look for things that un-indent. Of course, you have to compare the existing indentation to what the program "wants".

    If you are looking for an existing program, you want to look for a programming EDITOR. The only editor I know of that has that feature is Slick Edit [$300] . A couple of free editors that MIGHT have a beautify feature are Code Genie and Source Edit. (?) I use a free editor called Jens' File Editor. It has a feature called "AutoIndent" but that's NOT exactly what you're asking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  4. me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM