Thread: Dynamic pointer array in C

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    8

    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
    Last edited by MacFromOK; 04-05-2005 at 11:03 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to determine length of pointer array
    By Dr.Zoidburg in forum C Programming
    Replies: 12
    Last Post: 02-16-2009, 06:52 PM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  4. Pros pls help, Pointer to array
    By kokopo2 in forum C Programming
    Replies: 7
    Last Post: 08-17-2005, 11:07 AM
  5. sending or recieving a[][]to a function
    By arian in forum C++ Programming
    Replies: 12
    Last Post: 05-01-2004, 10:58 AM