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.
| Category | stdio.h I/O |
|---|---|
| Kind | Library function |
| Header | <stdio.h> |
| C standard | C89 / C90 |
📝 Syntax
int fputc(int c, FILE *stream);
⚙️ Parameters
| c Required | The character value to write, converted to unsigned char before output. |
|---|---|
| stream Required | An 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 stdio.h functions
📚 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.