I have a question: How C program fragment to demonstrate how the standard input of a process may be redirected away from the terminal keyboard to a file.
Am very new to C. I have given a lot of my time and tried until here. Not sure how to proceed further. Can someone please guide me on this?
#include <stdli.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
int main(){
int fd;
char str[255];
fd = open ("foo", O_WRONGLY | O_CREATE, 0766);
if (fd==-1){
perror("Error inopening the file ");
exit(1);
}
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
dup2(fd, STDOUT_FILENO);
.......
...
exit(0);
}