Jump to content
  • Advertisement
Sign in to follow this  
tanel1993

Using fread in c#

This topic is 3166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!