So, since the front page of /prague/ currently seems insufficiently programming related, what's the best way to read a string containing whitespace from standard input in C?
scanf() stops scanning at the first whitespace character. gets() is unsafe since it offers no protection against buffer overflows. fgets() has neither of the problems of the above, but copies the newline into the buffer, meaning the string can't be printed unless you sanitize it by stripping out the newline first. gets_s() seems not to have any of these problems, but wasn't introduced until C11.
Why wasn't there a simple safe string input function, that simply reads the first n characters (including whitespace) into a character buffer, in the C library from the beginning? It seems silly that they have such a variety of I/O functions, but none really suitable for such a simple task.
Also, what is even the purpose of the getc() function? It literally has the exact same behavior as fgetc(), since both take a file parameter, and furthermore, getc() goes against the convention that I/O functions only take a file parameter if they're the f-version (fprintf, fputs, etc), and I/O functions without an f prefix are assumed to work on stdin or stdout. So not only is getc() superflous, its name is misleading about how it is used. So why is it even included in the C standard library?