For my assignment, I have to read a text file one character at a time and display it in the console. Here's my code for this:
class TEXT
{
static StreamReader reader;
static void Main()
{
int ch, characters = 0;
// file that is being read in and displayed one character at a time in the console screen.
reader = new StreamReader("../../../data.txt");
StreamWriter writer;
// new file where hex characters will be written to.
writer = new StreamWriter("../../../s_drcyphert.txt");
do
{
//---------------------------------------
// read one character at a time.
ch = reader.Read();
//----------------------------------------
// write each char to the console screen
Console.Write((char)ch);
//----------------------------------------
// count the characters
characters++;
//--------------------------------------------------
// create a method, WriteByte() for this task. use parameters to pass in the character
// to be written and a reference to the output file.
WriteByte(ch, ref writer);
//---------------------------------------------------
} while (!reader.EndOfStream);
I have to output the text that was read into a new file using StreamWriter, one character at a time, and I have to output it in hex characters (using the WriteByte() method). Am I calling the method correctly? And if so, what should that method look like and what should be in that method? I've been reading non-stop and can't seem to grasp the ideas.