//This program shows you how input redirection works. #include #include #include #include int main() { int fd = -1; char sm[512]; printf("What's the message? "); scanf("%s", sm); printf("The message was: %s\n", sm); printf("Redirecting\n"); //opening a file fd = open("input_file.txt", O_RDONLY); //closing stdin close(0); //Duping the file descriptor for the file. Since we just closed stdin, the duped file descriptor is going to //be 0. dup(fd); close(fd); printf("What's the message? "); scanf("%s", sm); printf("The message was: %s\n", &sm); return 0; }