CSharp/C# >> Need Just one byte from Console.In

by Klaus H. Probst » Sat, 01 May 2004 05:21:32 GMT


Klaus H. Probst, MVP

"HarryS" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
> How do i read in just one byte from the Console without having to type a
carriage-return. The Read and ReadBlock for System.Console.In seem to
require a carriage-return to terminate the read and these are of no use to
> Thanks

CSharp/C# >> Need Just one byte from Console.In

by SGFycnlT » Sat, 01 May 2004 06:21:02 GMT

Thank you for your kindness. I couldn't find this earlier with much searching



Similar Threads

1. console app get byte array

hey all,

is there a way in a console app to download a file (byte array)?


2. Limit C# console app to one instance - CSharp/C#

3. Allow only one instance of console application to run

4. Fastest way to copy from a one dimension byte array to two dimension int array - CSharp/C#

5. One Byte Missing After Using FileStream

In the code below, I open a file using filestream, copy it to a byte
array, and the write that array out to a new file.  But when I check
the size of the original file and the new file, the new file has one
less byte than the original file (although the file itself still works
fine).  I was hoping someone could explain what is going on (why is
there a byte missing, and what might that byte be).

string originalFile = @"C:\MP3Test\Original.mp3";
string copiedFile = @"C:\MP3Test\Copied.mp3";

// Read file into byte array
FileStream fs1 = new FileStream(originalFile, FileMode.OpenOrCreate,
byte[] mp3ByteArray = new byte[fs1.Length];
fs1.Read(mp3ByteArray, 0, System.Convert.ToInt32(fs1.Length));

// Write same byte array to new file
int arraySize = new int();
arraySize = mp3ByteArray.GetUpperBound(0);
FileStream fs2 = new FileStream(copiedFile, FileMode.OpenOrCreate,
fs2.Write(mp3ByteArray, 0, arraySize);

// Compare size of original an new file
FileInfo fileInfo1 = new FileInfo(originalFile);
FileInfo fileInfo2 = new FileInfo(copiedFile);

Console.WriteLine("Size of original file: " +
// output====> 20629 bytes
Console.WriteLine("Size of copied file: " +
// output====> 20628 bytes.  One byte less than original file.



6. Only writing 1 byte to a file stream on one pc in office - CSharp/C#

7. RAD2007 / CBuilder - Mixing code with one byte alignment and quad word alignment


I have an old program that used to be based on byte alignment, and now 
must be based on quad word (eight byte) alignment.

My problem is with one particular structure that is used to read/write 
from a disk file, using the structure image.  For backwards 
compatibility, I need it to have one byte alignment (packed) instead of 
the default eight byte the rest of the project has (i.e., to read 
existing files).


I know how to use the pragma pack option to force one byte alignment for 
the structure and code involved.  What I'm wondering about is mixing 
stuff from the rest of the program.

For example, if I have an AnsiString declared in the eight byte 
alignment portion, and I pass it into the one byte alignment code (i.e., 
as a function argument), does the one byte code potentially have a 
different layout for the AnsiString data (as AnsiString is an object), 
thus causing mass confusion?

I believe I will be safe passing around integral types (like int, 
double, char *, etc.), but I'm fuzzy on what happens with objects (like 
AnsiString or TStringList objects, etc.).  I don't believe it's safe to 
pass structures around, as the eight byte code has it unpacked, but the 
one byte code would see it as packed (maybe?), but feel free to 
enlighten me :).


8. RAD2007 / CBuilder - Mixing code with one byte alignment andquad word alignment