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