C/Development/Exit Abort
Версия от 14:20, 25 мая 2010; (обсуждение)
Содержание
Abort current process returning error code: how to use abort
#include <stdio.h>
#include <stdlib.h>
int main () {
FILE *file;
file= fopen ("my.txt","r");
if (file == NULL) {
printf ("error reading file\n");
abort();
}
fclose (file);
return 0;
}
Assign function which is called when exit
#include <stdlib.h>
#include <stdio.h>
void done(void);
int main(void)
{
if(atexit(done))
printf("Error in atexit().");
return 0;
}
void done(void)
{
printf("Hello There");
}
Specifies a function to be executed at exit: how to use atexit
#include <stdio.h>
#include <stdlib.h>
void fExit1 (void) {
printf ("Exit function 1.\n");
}
void fExit2 (void) {
printf ("Exit function 2.\n");
}
int main () {
atexit (fExit1);
atexit (fExit2);
printf ("Main function.\n");
return 0;
}
Terminate calling process: how to use exit
#include <stdio.h>
#include <stdlib.h>
int main ()
{
FILE *file;
file = open ("my.txt","r");
if (file==NULL)
{
printf ("Error opening file");
exit (1);
}
return 0;
}