Re: getting variable length strings from stdin



On 18 Aug 2005 19:03:07 GMT, "Default User" <defaultuserbr@xxxxxxxxx>
wrote in comp.lang.c:

> siliconwafer wrote:
>
> > Hi All,
> > I want to take a string from stdin(say login Name).But I don't want a
> > static array of fixed size.I don't want to restrict user to a
> > perticular sizeof login name.
> > So I want to allocate memory dynamically to hold the name depending on
> > size of name.
> > One way of doing is:
> > malloc(strlen(gets(char*))+1);
>
> This doesn't make any sense. You'd already have to have a buffer of the
> correct size for gets() to read into.

No, no, NO, NO!!!

The horror, the agony, the sheer terror. Please retract the above
statement.

There is no such thing as "a buffer of the correct size" for calling
gets().

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages