Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practice02 / ex1-1.c
blob: 55f4ccf73cca1d3abd2ef5686a0bb073872bd26d (plain) (blame)
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
#include <fcntl.h> // open, close, O_RDONLY
#include <unistd.h> // read
#include <stdio.h> // printf, perror

int main(int argc, char* argv[]) {
	int f1 = open(argv[1], O_RDONLY);
	if (f1 < 0) {
		perror("open");
		return 1;
	}

	int f2 = open(argv[1], O_RDONLY);
	if (f2 < 0) {
		perror("open");
		return 2;
	}

	char buf1, buf2;
	while (read(f1, &buf1, 1) && read(f2, &buf2, 1)) {
		printf("%c%c", buf1, buf2);
	}

	close(f1);
	close(f2);
}