#include #include #include #include int main(int argc, char ** argv) { int fd = 0; int nbytes; char * string = "hello, tape\n"; /* check argumentst */ if (argc != 2) { printf("%s: \n", argv[0]); return 1; } /* open op device and check for a valid file descripter */ printf("opening %s\n", argv[1]); if((fd = open(argv[1], O_RDWR|O_CREAT | O_TRUNC, S_IRUSR|S_IWUSR )) <= 0) { perror("open: "); return 1; } printf("fd = %d\n", fd); /* write the string to file */ if((nbytes = write(fd, string, strlen(string))) < 0); { perror("write: "); } printf("write %d bytes, to %s, fd = %d\n", nbytes, argv[1], fd); close(fd); }