fputc in C Programming

The C fputc function is used to write the character(s) to the specified stream at the current position in a file, and then advanced the pointer position.

In this article we will show you, How to write the character, or character array (string), or string data to a File using fputc in C Programming with example. Use fputs function to write complete string.

TIP: You have to include the #include<stdio.h> header before using this fputc function.

Syntax of fputc in C Programming

The syntax behind the fputc in C Programming language is as shown below.

int fputc(int char, FILE *stream)

or we can simply write it as:

int fputc(int char, <File Pointer>)

From the above C fputc function code snippet,

char: Please specify the character(s) you want to written to the file

stream: Please specify the pointer to a FILE object, or simply say, file pointer that holds the file address and the operation mode

We are going to use the following specified file to demonstrate this C fputc function.

From the above screenshot you can observe that, sample.txt file is in our Documents folder and it is empty.

fputc in C Programming Example

The C fputc method is used to write character(s) to the user specified file. This C program will help you to understand the same.