c++ - reading a binary unknown size file in c# -


i have switched c# c++. have done task in c++ , same have translate in c#.

i going through problems.

i have find frequency of symbols in binary files (which taken sole argument, don't know it's size/length).(these frequency further used create huffman tree).

my code in c++ below :

my structure this:

struct node      {         unsigned int symbol;     int freq;         struct node * next,  * left, * right;   }; node * tree; 

and how read file :

file * fp; fp = fopen(argv, "rb"); ch = fgetc(fp);  while (fread( & ch, sizeof(ch), 1, fp)) {     create_frequency(ch); }  fclose(fp); 

could 1 please me in translating same in c# (specially binary file read procedure create frequency of symbols , storing in linked list)? help

edit: tried write code according henk holterman explained below still there error , error :

error cs1501: no overload method 'open' takes '1' arguments /usr/lib/mono/2.0/mscorlib.dll (location of symbol related previous error) shekhar_c#.cs(22,32): error cs0825: contextual keyword 'var' may appear within local variable declaration compilation failed: 2 error(s), 0 warnings 

and code is:

static void main(string[] args) {     // using provides exception-safe closing     using (var fp = system.io.file.open(args))     {         int b; // note: not byte         while ((b = fp.readbyte()) >= 0)         {             byte ch = (byte) b;             // use byte in 'ch'             //create_frequency(ch);         }     }  } 

and line corresponding 2 errors :

using (var fp = system.io.file.open(args)) 

could 1 please me ? beginner c#

string filename = ... using (var fp = system.io.file.openread(filename)) // using provides exception-safe closing {     int b; // note: not byte      while ((b = fp.readbyte()) >= 0)     {         byte ch = (byte) b;         // use byte in 'ch'         create_frequency(ch);     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -