1 #include <fcntl.h>
2
3 main(int argc, char argv[])
4 {
5 char buf[1];
6 int fd, count = 0;
7
8 if (argc > 1)
9 fd = open(argv[1], O_RDONLY);
10 else
11 fd = 0; / Use standard input */
12
13 while (read(fd, buf, 1) > 0) {
14 if (count < 5) write(1, buf, 1);
15 if (buf[0] == '\n') count++;
16 }
17 }
Here buf can store only one character.
But if i run it as:-
"prog_name /etc/passwd" how does it give first five lines.