Function to read lines of text

This is a discussion on Function to read lines of text within the C Programming forums, part of the General Programming Boards category; Could someone tell me which function shoud I use to read text from any txt file?
With fscanf() I read ...

Function to read lines of text

Could someone tell me which function shoud I use to read text from any txt file?
With fscanf() I read data with specific format. I don't want that...I want to read just any text and output some strings in a specific way.

In my program I want to read text from a file and inverse those words that are equal to a word given. I don't know the length of each line, so I can't assign a BUFSIZ which will always be enough.
For example, if I read 1000 characters each time, how can I deal with the situation in which a word exists between line[998] and line[1002]? The word will be separated into two pieces and won't be checked correctly for equality with the word given.

I have a .txt file which includes text. It can have one line, or two or ten. Maybe it's only one word. In any case I want to check if any of the word(s) in the text are equal to a specific word given to me. I thought that I could read a line or 1000 chars each time using fgets() and the splitting the string into words using strtok(). But with that possible solution, I need to find a way to deal with the situation which I describe in my previous post.

fgets reads text up to the size of the buffer provided, or until it hits a newline character. If it fills the buffer, there will be no newline in the buffer. At that point, you can allocate memory for a secondary buffer to hold what you have + some extra amount, copy what you have into the new buffer and read again into the original buffer. Repeat as necessary. When you've hit the newline, copy the final data into the secondary buffer and use it.

fgets reads text up to the size of the buffer provided, or until it hits a newline character. If it fills the buffer, there will be no newline in the buffer. At that point, you can allocate memory for a secondary buffer to hold what you have + some extra amount, copy what you have into the new buffer and read again into the original buffer. Repeat as necessary. When you've hit the newline, copy the final data into the secondary buffer and use it.

Yes, that's clever enough. When fgets() hits a newline character, it stops reading right before '\n' without reading it or it reads that too?