Dynamic pointer array in C
Hi Guys,
My compiler is LCC (a C compiler).
I am currently using a large (global) array of pointers to load a text file (in a function) as follows:
1. Using a 64k local UCHAR var to hold a line of the file with fgets.
2. Malloc a pointer from the array to the proper size and copy the UCHAR var to the pointer.
3. Continue this for each line of the file.
4. Record the number of lines so I can use free() in a loop on program exit.
The problem: The text file can vary from a few lines to a few thousand. I'd like to be able to set the size of the global pointer array to match the number of lines in the file to avoid using an unnecessarily large pointer array.
The pointer array must be global, and the solution must be in C (no C++).
Any ideas?
Thanks, Mac