The gets
function was first deprecated in C99 and finally removed in C11. Yet there is no direct replacement for it in the C library.
fgets()
This question largely calls for speculation short of a citation from committee minutes or something, but as a general principle, the committee (WG14) generally avoids inventing new interfaces and prefers to document and make rigorous existing practice (things like snprintf
, long long
, the inttypes.h
types, etc.) and sometimes adopt from other standards/interface definitions outside of C (e.g. complex math from IEEE floating point, atomic model from C++, etc.). gets
has no such replacement to adopt, probably because fgets
is generally considered superior (it's non-lossy when the file ends without a newline). If you really want a direct replacement, something like this works:
char buf[100];
scanf("%99[^\n]%*1[\n]", buf);
Of course it's klunky to use, especially when the buffer size is variable.