Reading big files in c




















Improve this question. Fil Nick Fil Nick 45 1 1 silver badge 5 5 bronze badges. I am a bit confused about using xor. How does this enter the story? I wanted to use Xor in this program later on, but I refrained from doing so in order to better understand some of the problems with the file reader.

I do not however intend to limit the use of this code just for Xor, it more or less of an example of what could be applied too. I do apologize for not making that clearer.

If I sounded rude at all in any of my responses or text I do also apologize for that, I simply want to be very clear. I never realised that fat kids in candy stores were well known for eating memory. I miss your point. And your second code seems overly complicated, just for reading file in chunks. Show 9 more comments. Active Oldest Votes. Improve this answer. Ilya Popov Ilya Popov 3, 1 1 gold badge 15 15 silver badges 29 29 bronze badges.

It works pretty well with regular text, but it flat out does not work on some binary files like exe's. I am pretty sure it should work fine. Can you elaborate on how does it fail? Contact us. Recent Posts. Go to Page Imagine this scenario - You are faced with the task of writing a parser that will be capable of handling files of unlimited size. Every record in the file has a varying length. You cannot read the entire file into memory and you cannot use fgets or fgetcsv type functions to read records one at a time.

As part of this post I will present a simple, yet highly effective, algorithm that will enable you to process files of unlimited size at ease. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.

Learn more. Asked 9 years, 5 months ago. Active 4 years, 7 months ago. Viewed 22k times. I have to write C code for reading large files. Improve this question. There are some serious problems with your code that I can see.

First of all you allocate a buffer to read into, using size as the size. Then you read info the buffer, using a fixed size disregarding the allocated size of the buffer you read into.

Think about what will happen if size is less than k. Second, as the file is newly open you do not need to seek to the beginning.

Third, you then seek to size , but is size the number of records in the file or a number of bytes? You use size differently when allocating the buffer. Insults are not welcome. Don't tell someone to read the manual. Chances are they have and don't get it.

Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid. Related Questions. How to read from text file and get expected output. Help without outputting a file to be read in text editor. How to read a text file and display in a textblock? How to read binary text file into datagridview? How do I C program that reads some text from a file and count the number of same words, word count, sentence count, numbers.

How to read a specific line in the text of a file? Reading a text file in C. Create text file in C without pointer.



0コメント

  • 1000 / 1000