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.

Categorystdio.h I/O
KindLibrary function
Header<stdio.h>
C standardC89 / C90

📝 Syntax

int fputs(const char *str, FILE *stream);

⚙️ Parameters

str RequiredThe null-terminated string to write.
stream RequiredAn 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏