fputc() Write one character to a stream

fputc() Write one character to a stream

fputc() writes c to a stream as unsigned char, returning its int value or EOF on failure. It can write a null character and adds no newline.

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

📝 Syntax

int fputc(int c, FILE *stream);

⚙️ Parameters

c RequiredThe character value to write, converted to unsigned char before output.
stream RequiredAn open stream available for output.

Returns: Returns the character written as an unsigned char converted to int, or EOF if a write error occurs.

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

C
⚠️ Warning The stream must support output. On error, the return value is EOF and must not be treated as an ordinary character.
💡 Tip fputc() writes one character; use fputs() for a complete null-terminated string.

📚 Related Tutorials

❓ FAQ

QWhat is the difference between fputc and fputs?
Afputc writes one character supplied as an int; fputs writes characters from a string up to, but not including, its terminating null character.
QCan fputc write a null character?
AYes. A null character is a valid character with value zero, and fputc writes it to the stream just like any other byte value.
QWhat is the difference between fputc and putchar?
Aputchar(c) is equivalent to fputc(c, stdout) and always writes to standard output; fputc() can also target stderr or another output stream. Both return the written character converted to int on success or EOF on failure, so check the result for critical output.
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%

🙏 帮我们做得更好

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

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