GetLine(); Usage

Jun 5, 2012 at 12:33am
I was given a brief introduction to the GetLine(); function in my C course, but I wasn't clearly told how to use it. Someone told me that this function doesn't exist/work in C, and I have read that elsewhere, but I highly doubt that the lecturer is fibbing! Any help would be greatly appreciated! :)

Below is an example assignment, which I do not want someone to solve for me. I am merely asking for a hint on how to use GetLine(); in such a case.

Ask the user to enter the name of a solid - either "prism", "cube", or "cylinder", and print back the name.


In such a case, I'd imagine using GetLine();, as the programming assignment suggests, in the hint section. But, how? =P
Last edited on Jun 5, 2012 at 12:33am
Jun 5, 2012 at 12:55am
If your teacher is talking about std::getline().. that that is definitely not C, but rather is C++.

The C equivilent to std::getline would probably be gets()

getline (if using char arrays):
http://cplusplus.com/reference/iostream/istream/getline/

getline (if using strings):
http://cplusplus.com/reference/string/getline/

gets (if using C):
http://cplusplus.com/reference/clibrary/cstdio/gets/



Note that gets() has no way to protect against buffer overflow, and therefore is severely broken and should probably never be used.
Topic archived. No new replies allowed.