C programming stdio.h function - int fputc(int char, FILE *stream)

The fputc() function in C programming is used to write a character to a file stream. It takes two arguments: the character to be written and a pointer to the file stream to write to.

Here's the syntax of the fputc() function:

refer to‮igi:‬ftidea.com
int fputc(int c, FILE *stream);

Here, c is the character to be written to the file, and stream is a pointer to the file stream.

The function returns the character written on success, and EOF on error.

Example usage:

#include <stdio.h>

int main() {
    FILE *fp;
    int c;

    fp = fopen("test.txt", "w");

    if (fp == NULL) {
        printf("Error opening file\n");
        return 1;
    }

    fputc('H', fp);
    fputc('e', fp);
    fputc('l', fp);
    fputc('l', fp);
    fputc('o', fp);

    fclose(fp);

    return 0;
}

This program creates a file called "test.txt" and writes the characters "Hello" to it using fputc().