As you correctly pointed out yourself the array has 10 elements
int x[] = {22, 8, 87, 76, 45, 43, 34, 13, 51, 15};
and among the elements there is no sentinel value that is equal to '\0'
.`.
So the loop invokes undefined behavior due to accessing the memory outside the array.
You could append to the array an element with the value equal to 0 like
int x[] = {22, 8, 87, 76, 45, 43, 34, 13, 51, 15, 0 };
In this case the loop
while (x[count] != '\0') {
count++;
}
will count all elements except the last one. So you will need to increase the variable count
after the loop that the last element also would be count.
Or you could rewrite the loop like
while ( x[count++] );
To get the number of elements in an array you can obtain its size and then divide it by the size of its element. For example
size_t count = sizeof( x ) / sizeof( x[0] );
or
size_t count = sizeof( x ) / sizeof( *x );
or even like
size_t count = sizeof( x ) / sizeof( x[1000] );
because the operator sizeof
does not evaluate the used expressions.