Prompts user for a line of text from standard input and returns it as a string (char *), sans trailing line ending. Supports CR (\r), LF (\n), and CRLF (\r\n) as line endings. Stores string on heap, but library’s destructor frees memory on program’s exit.
Returns the read line as a string. If user inputs only a line ending, returns "", not NULL. Returns NULL upon error or no input whatsoever (i.e., just EOF).
// attempt to read string from stdin
string s = get_string("Enter string: ");
// ensure string was read
if (s != NULL)
{
printf("You entered: %s\n", s);
}