First of all I didn't top post!!!
Yes, you did. Top-posting is when you put your reply before what you're
following up to. When your text comes before that quoted text of the
post to which you're following up, that's top-posting.
[ ... ]
What's wrong with gets().
It's dangerous because you can't limit the amount of text it will read
in.
How is gets any more dangarous then the scanf that
the guy was using? You can't pass a buffer size to scanf either.
Quite the contrary -- you most certainly CAN pass a buffer size of
scanf. A typical, reasonably safe use of scanf would look something
like this:
char buffer[50];
scanf("%49[^\n] ", buffer);
Of course, you can use similar capabilities (including the buffer-size
limit) with fscanf, sscanf, etc.). I'd also note that while the use of
scanf above is quite safe, it's possible that its effects will confuse
the user -- depending on the situation, something like this:
scanf("%49[^\n]%*c", buffer);
might be preferable.
If the
question doesn't involve c++ why confuse the guy with a c++ class.
If it had been specified that the desired language was C, that would
rule out use of cin. I see no such limitation in the subject or
original post. In any case, you were the one who originally brought up
the possibility of using cin.
If you
have noticed I said "or use the cin object"! If he knows what cin is then he
would use it if he doesn't then he will ask what the heck is cin and then I
would explane how to use it and how to include it!
Saying "you can use the cin object" is NOT really an answer to the
original question at all. Use of cin vs. stdin is orthogonal to the
original question.
I have 13 years of C++, and I teach C++.
What exactly does "I have 13 years of C++" mean?