2 ms·
If you're going to modify the code anyway, to include the header and set the buffer size, why not just use fgets, which takes a buffer size? Current versions o
by JoshTriplett 10y ago
If you're going to modify the code anyway, to include the header and set the buffer size, why not just use fgets, which takes a buffer size?
Current versions of glibc actually mark gets as deprecated (so you'll get a warning if you use it), and don't provide it at all if building for C11 or newer.
- kazinator 10y agoGood questions. Since I don't use gets, I have to imagine myself fixing some legacy code. Firstly, I imagine that this code already defines the arrays, so all I have to do is edit the definition to use this use this fictitious GETS_MAX constant, for which I have to include one simple header (which might already be included for something else). No actual logic has changed. (On the other hand, the adjustment to the size of the array to GETS_MAX could be a problematic issue; it is not without risk of something breaking.) To use fgets, I have to edit the calls to add the size parameter. Moreover, I have to scan the buffer for the presence of a newline character and overwrite it with a null. gets does that and the code may be relying on it (using "relying" ironically, with regard to gets).