PDA

View Full Version : return from main



Unregistered
01-11-2002, 07:16 AM
dos prog on windows95 machine


A return value of 0 from main signals all is fine any other value indicates some sort of error but where do these returns from main go to I know they go to the operating system but where and why because my program/compiler will indicate any errors if there are any.

thanks for the help.
learner wanting to be a master.

Pappy1942
01-11-2002, 10:04 AM
Hi,
The return from main() running under DOS can be accessed in DOS using "errorlevel" and used with "if" in a DOS bat file.

myprog.exe
if errorlevel 4 goto four
if errorlevel 3 goto three
and so on

goto exit

:four
echo In four
goto exit

:three
echo In three
goto exit

and so on

:exit

Note that DOS will 'goto' on any errorlevel larger than the one given so the errorlevels should be checked in desending order.