You have a number of serious issues. In the first place, using menu recursively is not a good idea. It is not showing that you're a slick programmer, but, rather, the opposite. Every call you make is borrowing memory from the heap. Nowhere do you show that you're freeing it. You can't be doing it elsewhere, because elsewhere has no idea how many times you've done it, or where the hell it is.
As for scanf, as mentioned in the other thread, you are not testing it to see if if succeeded in meeting your request. It does not promise to do so. It promises to do so or tell you that it failed. You aren't asking. Read about the return value of scanf and use it. When you break the stream, it stays broken until you repair it. It will zoop right through susbsequent calls. You will wonder why. Ask it. One who fails to do so is either uninformed or schlocky. You have now been informed.
I am fond of saying that the geeks who wrote these utilitarian functions knew what they were doing and provided return values (or other mechanisms for testing success) for a purpose. ATOI is an exception. ATOI will return a zero on failure. It will also return a zero if you present it with an argument that evaluates to zero. There is no way to tell the difference. Bad function, bad function (slaps it on the wrist with a ruler, just like the nuns used to do). Worse, with a bad argument, you will get undefined operation. That means the compiler is entitled to melt your system into a slag heap and eat your dog before he gets to your homework. Fortunately, most won't do that. Investigate string streams, or drop back into a C-style sscanf, or something.
Another issue is your user. You are instructing him/her to type a number. BWAHAAAAHAAAAAAAAAHAAAAA!!!! You are planning for an input of no more than 256 bytes. MUHAAAAAAHAAAAAAAAHAAAAAAA!!!1111ELEVEN. What are you going to do if you get a user who is stupid or malicious or falls asleep with his/her head on the keyboard? I know what your program is going to do. It is going to run off into the weeds and barf on its shoes.
Your code hints that you are using C++. Use C++. Read some of Bruce Eckel's stuff.
Last edited by DaWei; 28Dec2006 at 22:02..