Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

c - Use of exit() function

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

#include<stdio.h>

void main()
{
    int goals;
    printf("enter number of goals scored");
    scanf("%d",&goals);

    if(goals<=5)
        goto sos;
    else
    {
        printf("hehe");
        exit( );
    }
    sos:
    printf("to err is human");
}

When I run it, it shows ERROR: call to undefined function exit().

Also, I want to know how I can create an option to close the window in which the program runs? For example, I made a menu-driven program which had several options and one of them was "exit the menu". How can I make this exit the program (i.e. close the window)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try using exit(0); instead. The exit function expects an integer parameter. And don't forget to #include <stdlib.h>.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...