OK, I'll justify myself.
is the slightly slower equivalent* of:Code:scanf("%s%s",string1,string2);
* Actually, gets() stops at a newline while scanf stops at whitespace.Code:gets(string1); gets(string2);
However, gets() is less dangerous because:
- Some compilers will warn about the danger of gets().
- gets() will be picked up by other coders while the _scanf bug will often be missed. This is demonstrated by this forum. Use of gets() is commented on immediately while the _scanf bug regularly goes without comment, even when highly experienced programmers have posted comment on the code.
- Code and security reviews are more likely to miss the improper scanf usage.
- Employers are more likely to employ people who can't use scanf than people who use gets().
- Documentation for gets() usually explicitly points out the risk. This is not the case for _scanf, although MSDN does get it right.
- The dangers of gets() are in the faq, as far as I can tell, _scanf does not get the same treatment.
To use _scanf safely with strings, you must specify a width, one less than the size of the buffer.
If you don't, you should use gets() as it is safer.Code:scanf("%98s%98s",string1,string2);