The problem is that when you call it recursively from inside the function, you don't do anything with the return value:
When you call the function recursively here, your second iteration will return a value to this calling line when it finds the zero value. At that point, you need to return that value to the first calling function rather than just dropping it. Reading elsewhere (I haven't done much recursion) it looks as if you should do:
Each time your function calls itself, it needs to be able to pass the return value up the call stack. Right now you only pass it back for the time when it actually finds the zero value, but if that was anything other than the first call, it will be lost when the second or subsequent function ends. So your
return() in the original code doesn't pass control back to the calling main code, it passes it back to the previous function, and so on, until all the calls are returned from.
Another way to look at it is to forget about the recursive aspect of things and consider two functions - getcat() and gettopcat(). If getcat() doesn't find the answer, it calls gettopcat(). It follows that when gettopcat() returns the value to getcat(), then getcat() must also return it.