Im working on this analyzer program that reads input from a file and breaks characters into various tables.
Ive got the output pretty much done, except there's an issue with some of it, and Im pretty sure its due to the input problem.
so heres what the input looks like
int fact( int x )
/* recursive factorial function */
{ if (x > 1)
return x * fact(x-1);
else
return 1;
}
void main( void )
{ int x;
x = read();
if (x > 0) write( fact(x) );
}
and Im supposed to echo (make a copy of the input to the output file...with one thing that shouldnt be there: the commented line / recursive factorial function /)
so in essence, it should look like this:
int fact( int x )
{ if (x > 1)
return x * fact(x-1);
else
return 1;
}
void main( void )
{ int x;
x = read();
if (x > 0) write( fact(x) );
}
The problem Im having is there is no ignore function in C# like in C++, so I dont know how to make the program ignore this comment line.
Additionally, the last bracket "}" of the void main function is not displaying.
its truncated somehow. so all i get is:
int fact( int x )
/* recursive factorial function */
{ if (x > 1)
return x * fact(x-1);
else
return 1;
}
void main( void )
{ int x;
x = read();
if (x > 0) write( fact(x) );
here is my code that reads in the input file, and outputs this echo/copy of the input:
internal static class Define_input_output
{
public const string inFile = "input.txt"; //set file to read
public const string outFile = "output.txt"; //set file to write to
}
public static void read_inputFile(StreamReader input, StreamWriter output)
{
char character;
string word = "";
character = (char)input.Read();
while (!input.EndOfStream)
{
if (character == '\n')
{
output.Write(character);
}
//else if (character == '/' && input.Peek() == '*') //if character is / and next character is *, this line is a comment
//{
// ; //ignore all characters until end of line
// THIS IS WHERE AN IGNORE FUNCTION SHOULD BE
//}
else if (character == ' ')
{
output.Write(character);
}
else
{
output.Write(character);
}
character = (char)input.Read(); //read in next character
}
}
public static void neglectComment(StreamReader input)
{
bool isComment = false; //initialize isComment to false
while (!isComment) //loop until comment has been removed from stream
{
isComment = true; //comment has been taken out
}
}
static int Main()
{
StreamReader input = new StreamReader(Define_input_output.inFile);//input file
StreamWriter output = new StreamWriter(Define_input_output.outFile);//output file
while (!input.EndOfStream) //read each line until end of file
{
read_inputFile(input, output);
}
input.Close(); //close input file
output.Close(); //close output file
return 0;
}
Thanks in advance