A C stream provides an interface for output without exposing its implementation. The standard output streams are stdout for usual output and stderr for urgent output; file streams extend the same approach to permanent storage. section 8.3.1 section 8.3.2
Use the stream-oriented functions to direct unformatted output:
- Call fputc to write one character or fputs to write a string; both take a stream argument. section 8.3.1
- Open a file with fopen and a mode such as "a" for appending. Check for failure, and use perror to report it. section 8.3.2
- Treat FILE as opaque: rely on its functional interface rather than implementation details. section 8.3.1
Append a log message
Open "mylog.txt" in append mode, check the returned stream, then write a line with fputs. A separate example redirects stdout to a file with freopen, allowing puts to write there. section 8.3.2
int fputc(int c, FILE* stream);
int fputs(char const s[static 1], FILE* stream);
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":9}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":0,\"ch\":17},{\"line\":0,\"ch\":21}],[{\"line\":1,\"ch\":34},{\"line\":1,\"ch\":38}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":1,\"ch\":4},{\"line\":1,\"ch\":9}],[{\"line\":1,\"ch\":10},{\"line\":1,\"ch\":20}],[{\"line\":1,\"ch\":23},{\"line\":1,\"ch\":29}],[{\"line\":0,\"ch\":17},{\"line\":0,\"ch\":21}],[{\"line\":1,\"ch\":34},{\"line\":1,\"ch\":38}]]"}
!@%STYLE%@!
The function signatures show how fputc and fputs receive a stream as an argument. section 8.3.1


















