I need to read a line of text (terminated by a newline) without making assumptions about the length. So I now face to possibilities:
fgets
and
I would allocate a large buffer and then use fgets, checking, reallocing and repeating if you haven't read to the end of the line.
Each time you read (either via fgetc or fgets) you are making a system call which takes time, you want to minimize the number of times that happens, so calling fgets fewer times and iterating in memory is faster.
If you are reading from a file, mmap()
ing in the file is another option.