-
Notifications
You must be signed in to change notification settings - Fork 1
/
ch4_17.c
45 lines (33 loc) · 886 Bytes
/
ch4_17.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
45
#include <stdlib.h>
#include <stdio.h>
int main(){
FILE *fp;
int n;
long cur;
char buf[BUFSIZ];
if((fp = fopen("linux.txt", "r")) == NULL){
perror("fopen: linux.txt");
exit(1);
}
cur = ftell(fp);
printf("Offset cur = %d\n", (int) cur);
n = fread(buf, sizeof(char), 5, fp);
buf[n] = '\0';
printf("-- Read Str = %s\n", buf);
fseek(fp, 1, SEEK_CUR);
cur = ftell(fp);
printf("Offset cur = %d\n", (int) cur);
n = fread(buf, sizeof(char), 6, fp);
buf[n] = '\0';
printf("-- Read Str = %s\n", buf);
fseek(fp, 1, SEEK_CUR);
cur = ftell(fp);
printf("Offset cur = %d\n", (int) cur);
n = fread(buf, sizeof(char), 11, fp);
buf[n] = '\0';
printf("-- Read Str = %s\n", buf);
rewind(fp);
cur = ftell(fp);
printf("Rewind Offset cur = %d\n", (int) cur);
fclose(fp);
}