This blog is under construction

Monday 30 April 2012

exit example in C

Header file:
    stdlib.h

Synopsis:
     void exit(int status);

Description:
       It terminates the program normally.  All open stdio stream are flushed and closed properly.


exit function C example:


  #include<stdio.h>
  #include<stdlib.h>
  int main() {
        char str[100];
        int status;
        printf("Enter the your input(1/0):");
        scanf("%d", &status);
        if(status == 1)
                exit(EXIT_SUCCESS);
        else if(status == 0)
                exit(EXIT_FAILURE);
        printf("Exit function not hit\n");
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter the your input(1/0):1



No comments:

Post a Comment