Doesn't your compiler display any warning at this line?

b=dectobin(dig);
It's totally wrong because you are assigning pointer to value.