My question pertains to using a file descriptor which could be stdin or an opened file.
I am trying to figure out:
- Under what conditions does reading from a stream cause stalling. Why does
cin >> x
wait for user input, butfgets(line, len, file)
on an opened file never stalls to my knowledge. (I know stalling would not make sense for reading a file, but I'm trying to figure out how streams work here.) - How do you detect the end of the stream for opened file versus Stdin? It seems like when you read from Stdin, if you're at the end, it waits for input. If read from a file and you're at the end, a EOF is triggered somehow and it doesn't stall. And I think end of stream for Stdin would not necessarily mean the end of input, just that the program has read all available input so far, right?