Re: scanf() vs gets()
CBFalconer wrote:
[color=blue]
> Teh Charleh wrote:[color=green]
>>[/color]
> ... snip ...[color=green]
>>[color=darkred]
>> > By the way, don't use gets(). It cannot be used safely, except
>> > by Dan Pop.[/color]
>>
>> My book here C programming in easy steps is definately recommending
>> it over scanf if I want to input more than one word as a string![/color]
>
> Never use gets. See the FAQ for reasons. Avoid scanf for
> interactive work. You can use sscanf (or other routines) to parse
> what a gets /replacement/ provides.
>
> Any replacement for gets requires something extra from the
> programmer to control it, such as supplying a buffer size
> (fgets). Richard Heathfield has a readline routine,[/color]
It's actually called fgetline(). I'll tell you what - I'll link to your page
if you link to mine. Deal?
[color=blue]
> and I provide
> a ggets() routine. ggets requires only that you supply the
> address of a pointer, and eventually free the memory that pointer
> points to. It is built upon the use of fgets. You can get the
> source code and usage examples at:
>
> <http://cbfalconer.att. net/download/>[/color]
Hmmm. Seems to be down. I'll add the link once I know the exact page (which
I can't find out while the server is down, obviously - unless you tell me
here).
[color=blue]
> Please tell us the name, author, publisher etc. of your C book so
> that we can recommend burning it.[/color]
Please hold the burn. The last two occasions I recall where someone said
something similar, the books in question turned out to be <cough> "C
Unleashed" and "The C Programming Language" and, in each case, the newbie
had misunderstood the book.
--
Richard Heathfield : binary@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
CBFalconer wrote:
[color=blue]
> Teh Charleh wrote:[color=green]
>>[/color]
> ... snip ...[color=green]
>>[color=darkred]
>> > By the way, don't use gets(). It cannot be used safely, except
>> > by Dan Pop.[/color]
>>
>> My book here C programming in easy steps is definately recommending
>> it over scanf if I want to input more than one word as a string![/color]
>
> Never use gets. See the FAQ for reasons. Avoid scanf for
> interactive work. You can use sscanf (or other routines) to parse
> what a gets /replacement/ provides.
>
> Any replacement for gets requires something extra from the
> programmer to control it, such as supplying a buffer size
> (fgets). Richard Heathfield has a readline routine,[/color]
It's actually called fgetline(). I'll tell you what - I'll link to your page
if you link to mine. Deal?
[color=blue]
> and I provide
> a ggets() routine. ggets requires only that you supply the
> address of a pointer, and eventually free the memory that pointer
> points to. It is built upon the use of fgets. You can get the
> source code and usage examples at:
>
> <http://cbfalconer.att. net/download/>[/color]
Hmmm. Seems to be down. I'll add the link once I know the exact page (which
I can't find out while the server is down, obviously - unless you tell me
here).
[color=blue]
> Please tell us the name, author, publisher etc. of your C book so
> that we can recommend burning it.[/color]
Please hold the burn. The last two occasions I recall where someone said
something similar, the books in question turned out to be <cough> "C
Unleashed" and "The C Programming Language" and, in each case, the newbie
had misunderstood the book.
--
Richard Heathfield : binary@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Comment