-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest3.c
More file actions
40 lines (36 loc) · 747 Bytes
/
test3.c
File metadata and controls
40 lines (36 loc) · 747 Bytes
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
#include <stdio.h>
#include <fcntl.h>
int strcmp(char* a, char* b) {
while((*a == *b) && (*a != '\0')) {
a++;
b++;
}
return *a - *b;
}
int main(void)
{
char buf[16] = {0};
char* files[4] = {0};
int fd = 0;
int indx = 0;
int i,j = 0;
char *r = buf;
fd = open("script.txt", O_RDONLY);
read(fd, r, 16);
close(fd);
for(i = 0; i < 16; i++) {
if(strcmp((char*)&buf[i], "l") == 0) {
for(j = 0; j < indx; j++) {
printf("file%d\n", j);
}
} else if(strcmp((char*)&buf[i], "w") == 0) {
files[indx] = "WRITTEN";
indx += 1;
} else if(strcmp((char*)&buf[i], "d") == 0) {
for(j = 0; j < indx; j++) {
printf("file%d:\n\t%s\n", j, (char*)&files[j]);
}
}
}
return 0;
}