You are not initializing n to zero before using it. I wonder how this ever worked OK.
Question: What happens if array[n] is never zero? This can happen if the array is fully utilized. Also it should be array[i]. Variable i is the variable used to traverse the array. Variable n is just an accumulated result.
Finally, this is memory-inefficient. C++ will make a copy of the entire array every time this function is called.
+1 to strlen(). I did not mention it because I figured this was part of an assignment. Use strlen() if you are not bound to use sizeofarray() for academic purposes.