-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsignals.c
44 lines (38 loc) · 936 Bytes
/
signals.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void) {
int status = EXIT_SUCCESS;
FILE *in;
struct sigrecord {
int signum;
char signame[10];
char sigdesc[100];
} sigrec;
if ((in = fopen("signals.txt", "r")) == NULL) {
fputs("Cannot open signals.txt file\n", stderr);
return EXIT_FAILURE;
}
do {
int n = fscanf(in, "%d%9s%*[ \t]%99[^\n]",
&sigrec.signum, sigrec.signame, sigrec.sigdesc
);
if (n == 3) {
printf(
"Signal\n number = %d\n name = %s\n description = %s\n\n",
sigrec.signum, sigrec.signame, sigrec.sigdesc
);
} else if (n != EOF) {
fputs("Failed to match signum, signame or sigdesc\n", stderr);
status = EXIT_FAILURE;
break;
} else {
break;
}
} while (1);
if (fclose(in) == EOF) {
fputs("Failed to close file \n", stderr);
status = EXIT_FAILURE;
}
return status;
}