Thread: How to get length of array of char arrays

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    50

    How to get length of array of char arrays

    I have variable char ** string_list. Is there a function to obtain the number of "strings" in this list?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    There is no list. What you have is a pointer to a pointer. If there is some kind of list involved, you need to keep track of its length with another variable, or determine it in some other way (e.g., traverse the list until you reach a special value that denotes the end of the list; a similiar idea can be found in the use of a null character and strlen()).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Each row of a 2D structure, must be set with a size or an address. So the program must have some number that refers to the number of rows (number of strings), it's pointing to. It may be set with a #define ROWS 25 line of code, or by using a constant integer, perhaps like:

    Code:
    for(i = 0; i < ROWS; i++)
      array[i] = malloc(COLS * sizeof(int));
    There is no function to tell you what that number might be, however.

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    50
    Sorry for being misleading, I was going to put the word list in my post in quotes. I suppose I should have, or stuck to the vernacular used in the title.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. help with array of char and char **
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 04-20-2002, 02:23 PM