Skip to content

Latest commit

 

History

History
38 lines (24 loc) · 1010 Bytes

File metadata and controls

38 lines (24 loc) · 1010 Bytes

get_string(3)

NAME

get_string - prompts user for a line of text from stdin and returns it as a string

SYNOPSIS

#include <cs50.h>

string get_string(string prompt);

DESCRIPTION

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.

RETURN VALUE

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).

EXAMPLE

// 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);
}

SEE ALSO

get_char(3), get_double(3), get_float(3), get_int(3),
get_long_long(3)