/* changes the case of each letter Illustrates accessing files with user specified buffers with fns defined in file control header file */ #include #include #define BUFSIZE 1024 main(int argc, char **argv) { char mybuf[BUFSIZE], *p; int in_fd, out_fd, n; in_fd = open(argv[1], O_RDONLY); /* open for read only */ out_fd = open(argv[2], O_WRONLY | O_EXCL | O_CREAT, 0600); /* open for write only or for create exclusively with file prot 600 */ while ((n = read(in_fd, mybuf, BUFSIZE)) > 0) { /* use file identifier 0 - std input, 1 - std output, 2 - std error */ for (p = mybuf; p - mybuf < n; ++p) if (islower(*p)) *p = toupper(*p); else if (isupper(*p)) *p = tolower(*p); write(out_fd, mybuf, n); } close(in_fd); close(out_fd); }