Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Why does everyone say not to use gets?
Why does everyone say not to use gets?
✍: Guest
Unlike fgets(), gets() cannot be told the size of the buffer it's to read into, so it cannot be prevented from overflowing that buffer if an input line is longer than expected--and Murphy's Law says that, sooner or later, a larger-than-expected input line will occur. (It's possible to convince yourself that, for some reason or another, input lines longer than some maximum are impossible, but it's also possible to be mistaken, and in any case it's just as easy to use fgets.)
The Standard fgets function is a vast improvement over gets(), although it's not perfect, either. (If long lines are a real possibility, their proper handling must be carefully considered.)
One other difference between fgets() and gets() is that fgets() retains the '\n', but it is straightforward to strip it out.for a code fragment illustrating the replacement of gets() with fgets().
2015-10-16, 1481👍, 0💬
Popular Posts:
How Many Tags Are Defined in HTML 4.01? There are 77 tags defined in HTML 4.01: a abbr acronym addre...
What is a measure in OLAP ? Measures are the key performance indicator that you want to evaluate. To...
How did you implement UML in your project ? PART II Implementation phase / Coding phase (Class diagr...
Why is it preferred to not use finalize for clean up? Problem with finalize is that garbage collecti...
What is COCOMO I, COCOMOII and COCOMOIII? In CD we have a complete free PDF tutorial of how to prepa...