A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
fputs writes a null-terminated string to a stream. No format parsing. No variadic arguments. No percent-sign interpretation. It is faster than fprintf for plain strings because it skips the format engine entirely. It does not append a newline. If you want a newline, include it in the string or call fputc separately.
#include <stdio.h>int main(void) {FILE *fp = fopen("log.txt", "a");if (fp == NULL) {perror("fopen");return 1;}fputs("Application started.\n", fp);fputs("Loading configuration...\n", fp);fputs("Ready.\n", fp);fclose(fp);return 0;}
fputs returns a non-negative value on success and EOF on error. Check it in production logging code. A failed write to a log file might indicate a full disk or a permissions change, and your monitoring should catch that.
fprintf(fp, "Hello\n") and fputs("Hello\n", fp) produce identical output. The difference is that fprintf parses the format string looking for % specifiers, finds none, and then writes. fputs just writes. In a tight loop writing thousands of log lines, that parsing overhead adds up. Use fputs when there is nothing to format.
fputs is the minimal string-to-stream function. No frills, no formatting, no surprises. Use it for log lines, static headers, and any output that does not need interpolation. Next: puts, which is fputs pointed at stdout with an automatic newline.
Finish the lesson once you have worked through the material. This awards ★ 20 XP.