The man page says:
fgets() return s on success, and NULL on error or when end of file occurs while no characters have been read.
I wrote a small C file which calls fgets to test its behavior. I particularly wanted to see what happens when EOF occurs after some characters have been inputted. I used the eof key combination (Ctrl+D) on bash. I had to press Ctrl+D twice for fgets to return. It printed out the characters inputted until I pressed Ctrl+D twice. Pressing Ctrl+D once after some characters had been inputted had no effect at all. If I inputted some characters after this they were stored in the passed array. Why does fgets behave this way?
The behavior you describe has nothing to do with fgets. The shell does not close the input stream until you press ctrl-D the 2nd time.