What would be the most efficient method of reading a text file into a dynamic one-dimensional array? reallocing after every read char seems silly, reallocing after every read line doesn't seem much better. I would like to read the entire file into the array. How would you do it?
Reading a text file into an array in c
arraysc++
Related Question
- Javascript – How to append something to an array
- Javascript – How to insert an item into an array at a specific index (JavaScript)
- Javascript – Sort array of objects by string property value
- Sqlite – Improve INSERT-per-second performance of SQLite
- Javascript – Loop through an array in JavaScript
- Javascript – How to check if an object is an array?
- Javascript – How to remove a specific item from an array
- Javascript – For-each over an array in JavaScript
Best Solution
I don't understand quite what you want. Do you want to incrementally process the file, reading one line from it, then abandon it and process the next? Or do you want to read the entire file into a buffer? If you want the latter, I think this is appropriate (check for NULL return for malloc and fopen in real code for whether the file exist and whether you got enough memory):