Declaring an array of char and reading char from Binary Stream

N

nick.stefanov

Hello,

I am trying to read a binary file generated from Ethereal. I need a
structure to hold my frame and one of my variables which stores
source/destination address has to be of type char[6]. In my structure
i cannot figure out how to declare this. Trying char[] dest_addr = new
char[6] but I get an error cannot have instance field initializers in
structs.
If I just delare public char[] dest_addr and then try to read like so
binaryfile.ReadChars(6) what gets stored is System.Char[]. Any help on
how to declare and read is very appriciated.

Nick
 
J

Jon Skeet [C# MVP]

I am trying to read a binary file generated from Ethereal. I need a
structure to hold my frame and one of my variables which stores
source/destination address has to be of type char[6]. In my structure
i cannot figure out how to declare this. Trying char[] dest_addr = new
char[6] but I get an error cannot have instance field initializers in
structs.
If I just delare public char[] dest_addr and then try to read like so
binaryfile.ReadChars(6) what gets stored is System.Char[]. Any help on
how to declare and read is very appriciated.

What do you mean by "what gets stored is System.Char[]"? If you print
out a char array just by doing

Console.WriteLine (myCharArray);

it will indeed print out "System.Char[]". That doesn't mean it doesn't
have the right contents though - try

Console.WriteLine (new string(myCharArray));

instead.
 
N

nick.stefanov

Thanks for your reply,

I have something like this:

char dest = new char[12];
dest = file.ReadChars(12);

MessageBox.Show(new string(dest));


Argument '1': cannot convert from 'char' to 'char*'
Cannot implicitly convert type 'char[]' to 'char'
The best overloaded method match for 'string.String(char*)' has some
invalid arguments
Cannot implicitly convert type 'char[]' to 'char'

Any suggestions?
 
N

nick.stefanov

Tried that and not getting any output using MessageBox.Show(dest) or
MessageBox.Show(new string(dest)).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top