My question is exactly the same as this one. That is, I\'m trying to use scanf()
to receive a string of indeterminate length, and I want scanf()
to dyn
I think, in real world, one need to have some maximum limit on length of user input.
Then you may read the whole line with something like getline()
. See http://www.cplusplus.com/reference/iostream/istream/getline/
Note that, if you want multiple input from user, you don't need to have separate char
arrays for each of them. You can have one big buffer, e.g. char buffer[2048]
, for using with getline()
, and copy the contents to a suitably allocated (and named) variable, e.g. something like char * name = strdup( buffer )
.