#include #include #include #include #include int main(int argc, char *argv[]) { int filetoread; char c; int done = 0; int result; if (argc < 2) { printf("We need an argument.\n"); return -1; } /* open a file */ filetoread = open(argv[1], O_RDONLY); if (filetoread == -1) { printf("File is not found.\n"); return -1; } while (done == 0) { /* read the file */ result = read(filetoread, &c, 1); if (result < 1) done=1; else { /* print content to the screen */ result = putchar(c); if (result == EOF) { printf("Output failure.\n"); return -1; } } } /* close the file */ close(filetoread); return 0; }