Thread: 2D array pointer?

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    2D array pointer?

    hey...i need to create an array of locations on the hard drive. at least i think thats how i want to do it as i've tried learning linked lists before and they just dont click. idky, but i dont get it. lol but basically i have a program that lets you search non-executable files for a specified string / strings. after the user selects the root dir, i create a dir listing of all of the files of a certain type in that dir and then open the files and search for the string. what i need to do is have a way to keep track of the dir list so i thought, hey a 2D array pointer. when i need to store another location, i can just increase the size of the array and store the new dir where the file is stored so that when the program is closed i can remove the files. so really, my question is how do i make this? i know how to do a 1D array pointer, but not 2D. thanks :]
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    well its very similar - allocate an array of pointers to your double
    pointer, use a loop to step through that, and allocate arrays
    for each pointer.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You'll need realloc(), and a variable to hold the size of the array.

    Search the board for examples.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    Quote Originally Posted by Richie T
    well its very similar - allocate an array of pointers to your double
    pointer, use a loop to step through that, and allocate arrays
    for each pointer.
    for some reason this just isn't clicking.
    an array of pointers? like *ptr[10]; ?
    and by the double pointer, you mean **pointer , yes?
    would you mind a quick example?

    thanks guys
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #5
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Here's what i was talking about - read filker0's post, explains
    both allocation and deallocation, and also an alternative approach


    http://cboard.cprogramming.com/showt...allocation+2-d
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D array pointer
    By taurus in forum C Programming
    Replies: 15
    Last Post: 10-30-2008, 12:30 PM
  2. Dynamic pointer array in C
    By MacFromOK in forum Windows Programming
    Replies: 14
    Last Post: 04-09-2005, 06:14 AM
  3. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM