#fgets() or any other function for reading txt files
26 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
fgets() will read one line at a time, or the whole of the buffer. Or until you reach EOF. Whichever happens first.
So if your buffer is sufficiently large to hold the longest line in the file, then you needn't worry.
Obviously, you will need to call fgets() until you reach EOF.
so if which value i need to pass for fgets paraments
or n parameter is optional??
no, you can just pass it the size of the buffer you're reading into though
#define BUFFER_SIZE 256
char buffer[BUFFER_SIZE] = {0};
while (fgets(buffer, BUFFER_SIZE, file) != NULL) {
// process data
}
Something like this, ig.
Why?
if you do: pass it the size of the dynamically allocated buffer
Have you got ESP built in?
🥲 hmm just in case im not sure about the how long one line is
idk what is ESP?
Extrasensory perception.
A.k.a. foresight.
How would you know how long the next line is before you even read it?
in python we have one option that reads upto new line charter
so i can use python to find the maximum line then pass that variable
Okay, you could fgetc() and ungetc() to read ahead and find the next newline.
But really?
im just wondring if i use dynamic allocation then it is posible to read with fgets
Yes, but you are making life REALLY hard for yourself.
lol
nah nah im just thinking about that :_) what will happen if i dont know the size of maximum line
!solved