getline() and fclose()

Hi All,

When I do man getline on my Linux system (in BASH), I see an example C code where a file is being read using getline() function.

Now, my question is why there is no fclose() to close the open file pointer?

People who don't have a Linux system, this is the code that I am referring to:

getline(3): delimited string input - Linux man page

Omitted for brevity, I presume. You should add one of course.

But I should say that's a "bad" programming practise. :slight_smile:

It won't matter here, because when the application quits, it autocloses all files.

But if you were doing this in a loop or something, forgetting to close a file over and over, you could quickly exceed a system limit and your program would stop functioning properly.

So it's a good habit to get into. Always, always close your files when you're done with them.