Rerouting stdin and stdout from C

Why use freopen()? The C89 specification has the answer in one of the endnotes for the section on <stdio.h>: 116. The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value returned … Read more

How to read / parse input in C? The FAQ

The Beginner’s C Input Primer Text mode vs. Binary mode Check fopen() for failure Pitfalls Check any functions you call for success EOF, or “why does the last line print twice” Do not use gets(), ever Do not use fflush() on stdin or any other stream open for reading, ever Do not use *scanf() for … Read more