RE: [Dev-C++] how to do a shell like input..
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@at...> - 2003-04-26 10:17:05
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Christian Sch=E4fer
> Sent: Saturday, April 26, 2003 10:29 AM
> To: Dev-C++ Mailing List
> Subject: [Dev-C++] how to do a shell like input..
>=20
>=20
> hi Dev-C++,
> [this is a followup thread to 'stdin reset..']
>=20
> I want to programm a shell-like interface for my application, in which
> I know some special commands with options and arguments.
>=20
> the problem I have is, how do I create an input-buffer, that is able
> to hold whatever is read from stdin, since i can not say what would be
> the longest valid entry (say cat some large text...).
>=20
> is there a way to dynamically read the length of the inputstring up to
> the first '\n' and then malloc some string and THEN scanf() ???
You can use a temporary buffer in the automatic storage of a fixed size
where you will store using getchar(), and then use malloc() and =
realloc() to
allocate the necessary space on the free store and strcat() from the =
temp
buffer... In C++ you would simply do:
string s;
while(cin>>s)
;
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
Anti-racism movement: http://www.positive-youthfoundation.org
Iraq Peace Pledge: http://www.peacepledge.org
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
Anti-racism movement: http://www.positive-youthfoundation.org
Iraq Peace Pledge: http://www.peacepledge.org
|