0

Why can't I do

printf("Text: ");
string text = get_string();

in order to get a string, text, which contains what an user inputs? I saw Doug Lloyd do something similar in this video: https://www.youtube.com/embed/b7-0sb-DV84 (16:17) where he does:

printf("Give me an integer: ");
int x = getint();

When I compile my code, I get the error

error: expected expression
    string text = get_string();
                  ^
/usr/include/cs50.h:109:53: note: expanded from macro 'get_string'
#define get_string(...) get_string(NULL, __VA_ARGS__)
7

2 Answers 2

1

The version of the function in the video (posted Oct 2017) is an earlier version than the one you are using (released sometime in 2018). The earlier version did not accept a string as an argument (notice printf("Give me an integer: "); in the example code). The current version requires an argument. You can follow the history of this enhancement on github.

0

Try:

string text = get_string("Text: ");

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .