Use of exit() function

后端 未结 13 1395
离开以前
离开以前 2020-11-30 23:34

I want to know how and when can I use the exit() function like the program in my book:

#include

void main()
{
    int goals;
            


        
13条回答
  •  执笔经年
    2020-11-30 23:49

    Include stdlib.h in your header, and then call abort(); in any place you want to exit your program. Like this:

    switch(varName)
    {
        case 1: 
         blah blah;
        case 2:
         blah blah;
        case 3:
         abort();
    }
    

    When the user enters the switch accepts this and give it to the case 3 where you call the abort function. It will exit your screen immediately after hitting enter key.

提交回复
热议问题