I am trying to use the write() function from <unistd.h> to stream text from the command line into a file. I have tried multiple things along the lines of:
while(write(STDOUT_FILENO, argv[optind], strlen(STDIN_FILENO)) != 0)
{
    write(STDOUT_FILENO, "\n", sizeof("\n"));
}
but continue to get segmentation faults or infinite loops without allowing me to enter anything. I am required to do this without using read(), the only permission allowed is write for the user. I am trying to use Ctrl + D to signal end of input.
An example of how it would run is:
./a.out file.h
This line will append to the end of the file
<ctrl + d>
Then, when I open the file it should have This line will append to the end of the file at the end of it.
 
    