Windows explorer automatically closes command prompt programs as soon as they return an error code to the system (that's what your return 0; line is meant for) - this is normal behaviour. If you want your command prompt window to remain open, you should open the command prompt first (Accessories menu), and then run the program in there, a la MS-DOS.