forked from mbmcmullen27/effective-c
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfread.c
37 lines (31 loc) · 821 Bytes
/
fread.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct sigrecord {
int signum;
char signame[10];
char sigdesc[100];
} sigrecord;
int main(void) {
int status = EXIT_SUCCESS;
FILE *fp;
sigrecord sigrec;
size_t size = sizeof(sigrecord);
if ((fp = fopen("signals.txt", "rb")) == NULL) {
fputs("Cannot open signals.txt file\n", stderr);
return EXIT_FAILURE;
}
// read the second signal
if (fseek(fp, size, SEEK_SET) != 0) {
fputs("fseek in signals.txt file failed\n", stderr);
status = EXIT_FAILURE;
goto close_files;
}
printf(
"Signal\n number = %d\n name = %s\n description = %s\n\n",
sigrec.signum, sigrec.signame, sigrec.sigdesc
);
close_files:
fclose(fp);
return status;
}