1
Answer

2-3 line code help needed :)

SUNIL GUTTA

SUNIL GUTTA

10y
708
1
Hi

Below mentioned code is working fine i hope but in below code there is a section i was unable to do it i.e Kept in bold letters do once check and any help is much appreciated .

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;


class wk13asgn

{

// Instance variables for opening and reading the file

static string file_name;

static BinaryReader in_stream;

static FileStream fs;


// Instance variable used to find the end of file

static bool end_of_file = false;


// Instance variables used by getbit()

static byte current_bit_position = 0;

static byte current_byte;


static void get_file_name()

/*********************/

/*** GET FILE NAME ***/

/*********************/

{

Console.Write("Enter File Name: ");

file_name = Console.ReadLine();

}


static void open_input_file()

/*****************/

/*** OPEN FILE ***/

/*****************/

{

try

{

fs = new FileStream(file_name, FileMode.Open, FileAccess.Read);

in_stream = new BinaryReader(fs);

}


catch (Exception)

{

Console.WriteLine("Can't open {0}", file_name);

Environment.Exit(0);

}

}


static bool no_more_bytes(BinaryReader rb)

/**********************/

/*** NO MORE BYTES? ***/

/**********************/

{

return (rb.PeekChar() == -1);

}


static byte read_a_byte(BinaryReader rb)

/********************************************************************************/

/*** Function to read a single byte from the input stream and set end_of_file ***/

/********************************************************************************/

{

byte abyte;


if (!no_more_bytes(rb))

abyte = rb.ReadByte();

else

{

abyte = 0;

end_of_file = true;

}


return abyte;

}


static byte getbit()

/**********************************************************/

/*** Function to get a single BIT from the input stream ***/

/**********************************************************/

{

byte mask;


//here we use fill in this function so it returns

//either a zero or a one for each bit in the file.

}


static void process()

/********************/

/*** PROCESS FILE ***/

/********************/

{

byte bit;

int counter = 0;


while (!end_of_file)

{

bit = getbit();

if (!end_of_file)

{

Console.Write("{0}", bit);

counter++;

//We only separate bytes to make the output easier to read.

//Your program should treat each bit individually.

if ((counter % 8) == 0) Console.Write(" ");

}

}

Console.WriteLine();

}


static void Main(string[] args)

{

if (args.Length == 0)

get_file_name();

else

file_name = args[0];

open_input_file();


process();


in_stream.Close();

fs.Close();

}

}


Have a nice day & Ty for help


Answers (1)
Next Recommended Forum