Thread: Text Formatting Program Help

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1

    Text Formatting Program Help

    Hello,
    I am working on a program that takes text and modifies it so it can be printed. It adds lines between paragraphs, page numbers, etc.

    I am having problems modifying the actual text. I have an outline:
    Code:
    #include <stdio.h>
    
    void txt2prt(char *input, char *output);
    char *header(int page);
    char *footer(int page);
    
    int main(int argc, char *argv[]) {
        char *infile = "infile.txt";
        char *outfile = "output.txt";
        
        //argc counts executable as 1 arg
        if( argc == 2 ) {
            infile = argv[1];
        }
        
        if( argc == 3 ) {
            infile = argv[1];
            outfile = argv[2];
        }
        
        txt2prt(infile, outfile);
        
        return 0;
    }
    
    void txt2prt(char *input, char *output) {
        int currentPage = 1;
        while(*input){
    		do(*input
    
        //While read from infile, do header, parse and print and footer
    }
    
    char *header(int page) {
        char *retStr;
    
        //ADD HEADER AND PAGE NUM TO retStr
        
        return retStr;
    }
    
    char *footer(int page) {
        char *retStr;
        
        //ADD FOOTER AND PAGE NUM TO retStr
        
        return retStr;
    }
    I was going to use a series of condition statements to apply the various indents and blank lines, etc. I was just wondering how I would go about modifying the input text (getting the input, and outputting something else)

    Cheers,
    Larph

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well the first step would be to write a program which simply copies the input file to the output file one line at a time.

    Then you can add things like
    - a count of the lines read, and then work out where page boundaries go (for header and footer).
    - work out where paragraphs are (what is your assignment specification for this?), then add blank lines.

    Incremental development - begin by working out what series of small steps will get you to your goal.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with formatting text.
    By vrek in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2007, 11:44 PM
  2. Text Formatting & various questions.
    By Zeusbwr in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2005, 09:27 AM
  3. formatting text with cprintf()
    By Noobie in forum C++ Programming
    Replies: 1
    Last Post: 02-09-2003, 06:13 PM
  4. cprintf() formatting text
    By Noobie in forum C++ Programming
    Replies: 3
    Last Post: 02-04-2003, 09:10 PM
  5. need help with formatting text
    By Flikm in forum C++ Programming
    Replies: 1
    Last Post: 09-06-2001, 07:52 PM