The FAQ has examples of file system operations haha.

For the input dilemma, just malloc up a reasonable size, like 1000 bytes or something, and test your fgets() to see if the record you read was truncated haha. If it was, teehee, get a bigger buffer (like 2000 bytes) and redo the operation hoho. If it fails again, get 4000 bytes and repeat again harhar.

This is not a programming challenge that C cannot handle.