I want to know if it's possible to read a string of unknown size, until space or until newline is reached. What I did in c++ is this:
char * dynStr;
char buffer[20];
cin >> buffer;
dynStr = new char[strlen(buffer) +1];
strcpy(dynStr, buffer);
But the problem is, what if the entered input is bigger than 20? So I think it should be something like this:
do
{
cin.get ( buffer, 20, ' '); //im not sure this is the right approach
strcpy(.....); // if is not a first iteration
//add the new buffer to the end of dyn str..
} while( ! read ' ' or '\n' ) <--- this is what I have problem doing
I know in c++ I can use std::string
, but I'd like to know how to do this thing, so if you have any ideas, tell me :)