Header file:
stdlib.h
Synopsis:
void abort(void);
Description:
It terminates the program abnormally.
abort function C example:
#include<stdio.h>
#include<stdlib.h>
int main() {
int i, n;
printf("Enter the value for n:");
scanf("%d", &n);
for(i = 0; i < n; i++) {
printf("i = %d\n", i);
if (i == n/2) {
printf("Gonna abort program\n");
abort();
}
}
return 0;
}
#include<stdlib.h>
int main() {
int i, n;
printf("Enter the value for n:");
scanf("%d", &n);
for(i = 0; i < n; i++) {
printf("i = %d\n", i);
if (i == n/2) {
printf("Gonna abort program\n");
abort();
}
}
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter the value for n:10
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
Gonna abort program
Aborted
Enter the value for n:10
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
Gonna abort program
Aborted
No comments:
Post a Comment