-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5a.c
34 lines (34 loc) · 863 Bytes
/
5a.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
int main(int argc, char *v[])
{
if (argc < 2)
{
printf("File name not entered\n");
exit(0);
}
char buf[10];
int fd = open(v[1], 0666);
if (fd == -1)
{
printf("File not found\n");
exit(0);
}
printf("Reading first 10 Characters\n");
int n = read(fd, buf, 10);
write(1, buf, n);
printf("\nSkipping 5 Characters from current position\n");
lseek(fd, 5, SEEK_CUR);
n = read(fd, buf, 10);
write(1, buf, n);
printf("\nGoing to 5th Character from last\n");
lseek(fd, -5, SEEK_END);
n = read(fd, buf, 5);
write(1, buf, n);
printf("\nGoing to 3rd Character from start\n");
lseek(fd, 3, SEEK_SET);
n = read(fd, buf, 10);
write(1, buf, n);
}