cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Use dynamic memory allocation.
In C++ (didn't test):
char * getstring()
{
fflush (stdin); //don't have to do it
char * string=NULL;
char * temp=NULL;
int size =2
scanf(""); //to get buffer input
char ch;
do
{
delete [] string;
string = new char[size];
memcpy (string, temp, sizeof(temp));
delete[]temp;
ch = getc(stdin);
string[size-2] =ch;
temp = new char [size];
memcpy(temp, string, sizeof (string));
size++;
} while (ch!='\n'); //change the quiting value if you want to whatever
return string;
}
void main (void)
{
char * string = getstring();
}
Valmian
Junior Poster in Training
82 posts since Sep 2003
Reputation Points: 13
Solved Threads: 0
I know, I just had like 1 min so I wrote what came first to my mind.. anyways, I am known to use classes, new/delete and all else in C. (i never took time to learn iostream etc.. but I like objects.. my first though is C)
Ilya
Valmian
Junior Poster in Training
82 posts since Sep 2003
Reputation Points: 13
Solved Threads: 0