int values[20]; int values_length=sizeof(values)/sizeof(values[0]); sizeof(values) gets the total number of bytes occupied by the array, and sizeof(values[0]) gets the number of bytes occupied by the first element(which is the same as every other element). I hadn't thought of the case where a char array hasn't been initialized and is full of garbage values. The above solution will work for any array ...