Re: getting variable length strings from stdin
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Thu, 18 Aug 2005 21:12:01 -0500
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
.
- References:
- getting variable length strings from stdin
- From: siliconwafer
- Re: getting variable length strings from stdin
- From: Default User
- getting variable length strings from stdin
- Prev by Date: Re: Interface between a C library and board support package
- Next by Date: Re: hexadecimal to float conversion
- Previous by thread: Re: getting variable length strings from stdin
- Next by thread: Re: getting variable length strings from stdin
- Index(es):
Relevant Pages
|