Sign in to follow this  
tanel1993

Using fread in c#

Recommended Posts

When i was using fread to read files, i discovered that there's one really weird problem. To make sure what was going on i made a file that has bytes from 0 to 255 written inside and this is how i read it: IntPtr P = IntPtr.Zero; P = BinFile.fopen(@"C:\bleh.txt", "r"); byte b = 0; for (int i = 0; i < 255; i++) { b = 0; BinFile.fread(&b, sizeof(byte), 1, P); Console.WriteLine(b); } BinFile.fclose(P); Also this is how i use fopen and fread: [DllImport("MSVCRT.DLL")] public static extern IntPtr fopen(string Path, string Mode); [DllImport("MSVCRT.DLL")] public static extern IntPtr fread(void* Buffer, uint Size, uint Count, IntPtr Stream); Well anyways... when i was reading it and it was about to read byte with the value of 26, it fails to read it and it fails with the next ones too. It seems to fail every time there's byte 26 to read. Does anybody have any idea what's going on and how to make read it right?

Share this post


Link to post
Share on other sites
Quote:
Original post by tanel1993
I just realized that before you said it by the way.
And way to go solving the problem.


The problem is that you're using an old and decrepit C API in a modern managed language. I've pointed you towards a correct solution to your real problem, even if you can't realize it. Trying to get fread to work will just be a waste of your time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this