knowing the amount of array being occupied

This is a discussion on knowing the amount of array being occupied within the C Programming forums, part of the General Programming Boards category; How can i know how many element in an array are being occupied ?? Coz i read a string from ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    41

    knowing the amount of array being occupied

    How can i know how many element in an array are being occupied ?? Coz i read a string from a file and store it in an array. I would like to know how many of the array are being occupied.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Generally you have no way of doing this, unless you implement some way for this yourself (like having a bolean array, where True = used, False = not used.

    With strings however, they always end with a NULL terminator ( '\0' ) when the string ends. The easiest way of getting the size used is to call strlen(). It calculates the number of characters before this NULL terminator.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  3. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  4. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM
  5. mode of an array
    By Need Help in forum C Programming
    Replies: 15
    Last Post: 09-17-2001, 08:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21