void tohex(int d){
for(;d >= 16;d = d/16)push(d);
for(;putchar(hex[d%16]),!stackempty();d = pop());
}

>どこか入力ミスでもしてるのでしょうか。
main関数より先にtohexを定義するよろし。