fputs() Write a string to a stream
fputs() Write a string to a stream
fputs() writes a string without its null terminator and adds no newline. It returns nonnegative or EOF; buffered data may not have reached the device.
| Category | stdio.h I/O |
|---|---|
| Kind | Library function |
| Header | <stdio.h> |
| C standard | C89 / C90 |
📝 Syntax
int fputs(const char *str, FILE *stream);
⚙️ Parameters
| str Required | The null-terminated string to write. |
|---|---|
| stream Required | An open stream available for output. |
Returns: Returns a nonnegative value on success, or EOF if a write error occurs.
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
Hello, stream!
⚠️ Warning str must point to a valid null-terminated string, and stream must support output.
💡 Tip The example explicitly includes a newline in the string; without it, fputs() would not add one.
🏷️ Related stdio.h functions
📚 Related Tutorials
❓ FAQ
QDoes fputs automatically append a newline?
ANo. Include a newline yourself when needed, as in fputs("text\n", stream).
QWhat is the difference between fputs and puts?
Afputs writes to a chosen stream without adding a newline; puts always writes to stdout and appends a newline.
QDoes a nonnegative fputs return value mean the data has reached the disk?
ANot necessarily. A nonnegative return only means this call reported no output error; data may remain in a user-space buffer. Check fflush() when errors must be detected promptly, and check fclose() after finishing file output, since a full device or low-level failure may surface later.