Thread: Help With Text Files C++

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    20

    Help With Text Files C++

    Ok, so I'm writing a text preprocessor which seems pretty easy...identify certain tags from a source file and format the output file accordingly.

    Basically it's supposed to work like this: The first character is read in main. If a character is == '<', then Brace is called to determine what tag needs processing. Inside Brace is where I'm having the problems, as I haven't declared input and output within that function. When I re-declare input and output in Brace it doesn't work properly, as it starts reading from the beginning of the file again which causes the switch to always result in a default.

    I guess I have absolutely no idea how to handle this situation. Any and all help is very much appreciated. Just for the record, I have no problem making an exact copy of the source file in the destination file, and know that Brace is called correctly (debugging) but it doesn't get past that switch correctly. Here's what I have so far:

    Code:
    #include<iostream>
    #include<fstream>
    #include<cctype>
     
    void Brace(char);
    void Title(char); 
     
    using namespace std;
     
    int main()
    { 
     
        ifstream input;
        ofstream output;
     
        input.open("source.dat");
        output.open("destination.out");
     
        char character;
     
        input >> character;
     
            while(input) 
            { 
                    switch(character)
                   { 
                     case '<': Brace(character);
                     output << character;
                     break; 
     
                    default: output << character;
                    break;
     
                   } //end switch
            
                    input >> character;
        
            } //end while
     
                 return 0; 
     
    } //end main
     
    void Brace(char character)
    { 
        input >> character;
     
        switch (character)
        {
             case 'T':
             case 't':  Title(character);
             break;
     
             default: output << character; 
             break;
    
        }//end switch
         
    return;
     
    }//end Brace
    
    void Title(char character) 
    {  
        input >> character;
            if (character == '>')
            {
                output << character;
            } //end if
                
            while(character != '<')
                { 
                    input >> character;
                    output << toupper(character);
                } //end while
     
            return;
    
        } //end Title
    Last edited by liquidspaces; 03-10-2003 at 11:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Reading text files?
    By Kate in forum C Programming
    Replies: 3
    Last Post: 06-30-2006, 01:22 AM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  4. reading certain parts of text files
    By Captain Penguin in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2002, 09:45 AM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM