Mail Archives: djgpp/2000/07/05/03:45:31
Evert Glebbeek wrote:
> >scanf(name);
> AFAIK, this is incorrect. I'm also not sure what it's supposed to do.
It's correct as long as 'name' points to an appropriate string.
In the case under consideration, however, 'name' doesn't point
anywhere in particular, so it would probably generate a SIGSEGV.
> >scanf("%s",name);
> Provided name points to an array of char (a string), this should be
> correct, however, I usually find it more convenient to use gets(name).
Never use gets - you don't know how long the string might be.
(Same problem with scanf("%s",buffer).)
> I usually deal with this by simply setting the string size
> redicilously large so it will never be overwritten in normal useage
But what about abnormal usage?
> (eg, a 256 byte string when reading a 2 digit number).
So why not use fgets(buffer,256,stdin)?
> >If someone could example/show me the standard way of dealing with
> >basic text input I would be very greatful.
> Well, like I said earlier, I'm not sure there is a standard way, but
> anyway, this is the way I do it.
The usual way is to use fgets. There is the question of what you
should do if the input string was too long, but that depends on
circumstances.
S.
- Raw text -