Well, the first thing you need to know is that getline() is not a standard C function (as of the C99 standard, at least to the best of my knowledge). It is an extension added in the GNU version of the stream I/O library, and while it is widely supported, it is not necessarily part of any given compiler's library, and is not that widely used.
(There is also a getline() function in the C++ <iostream> library, where it is standard, but it is a completely different thing than the C function. If you aren't sure which language the code you're reading is in, then chances are it's C++; post part of it and someone here should be able to tell you.)
The main advantage of getline() is that it is more secure than, say, gets() , in that it takes a size_t* argument that indicates the actual size of the buffer the line is being read into, and calls realloc() to re-size the buffer if the input exceeds the original buffer size (this assumes that the buffer was dynamically allocated in the first place, otherwise it would fail rather atrociously). This ensures that a buffer overrun cannot happen (short of running out of memory entirely), eliminating a common source of bugs and security flaws.
pardon sir, I am reading C book by K & R , I ve seen using getline() in many places and i dont understand it's now where to use this getline().
So you've seen the book use it, and don't know where to use it? Well, a good start would be in the same situations that the book uses it. Alternatively, you could strive to understand the implementation provided in the book and then use it where you would otherwise write similar code manually.
I mean, it's really just a function that reads a (potentially partial) line of characters from standard input.