Once again, I'm having trouble on my next assignment for class.
This is what I have to do:
Read and process a text file one character at a time:
1.) output the file to the screen one character at a time (as a char) as the file is read.
2.) output the file to another file called NEWFILE one
character at a time in HEX with a space between each hex character pair.
* create a method, WriteHex() for this task. use parameters to pass in the character
to be written and a reference to the output file.
3.) count each character, word & line in the file. characters can be counted in Main()
*create a method, Counts(), to count the lines and words and pass in the char,
and a reference parameter to the word and line count.
I have no idea how to even begin this.... I know I have to use the Read() method from the StreamReader class. Every time I go to output the text file as it's read using Read() method, it prints out a bunch of numbers. This is what I have so far:
using System;
using System.IO;
class TEXT
{
static void Main()
{
StreamReader reader;
reader = new StreamReader("../../../data.txt");
do
{
int s = reader.Read();
Console.WriteLine(s);
} while (!reader.EndOfStream);
reader.Close();
reader.Dispose();
}
static void WriteHex(int x)
{
}
static void Counts(int lines, int words)
{
}
}
All help is appreciated! Thanks!