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.
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.
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.