memset
(
buf
,
0
,
sizeof
(
buf
)
)
;
if
(
(
fd
=
open
(
argv
[
1
]
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0666
)
)
<
0
)
perror
(
"open"
)
;
return
-
1
;
while
(
fgets
(
buf
,
20
,
stdin
)
!=
NULL
)
if
(
strcmp
(
buf
,
"quit\n"
)
==
0
)
break
;
write
(
fd
,
buf
,
strlen
(
buf
)
)
;
close
(
fd
)
;
return
0
;
#include <stdio.h>#include <fcntl.h>#include <unistd.h>#include <string.h>#define N 128int main(int argc, const char *argv[]){ int fd; char buf[N] = { 0 }; memset(buf, 0, sizeof(buf)); if ((fd = open