fgets
is a stdio function, so it uses the stdio buffer, which lives in the process's address space. When you exec, that buffer disappears with the rest of the original program, and the exec'ed program allocates its own stdio buffer.
If your file is seekable, then fseek
to position 0 relative to SEEK_CUR
before the exec might help (it can reposition the underlying fd to the correct point to continue reading from where stdio left off).