Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Different functions & their examples

The fputc() function

This function is used to write a single character to the specified file. If this function fails to write a character into a file, it returns EOF.

Syntax

int fputc(int c, FILE *fp)

Example No. 1

#include<stdio.h>
int main()
{
    FILE *fp;
    fp=fopen("D:\\C Programming\\file1.txt","w");
    if(fp==NULL)
    {
        printf("\n Unable to open the FILE");
        return 1;
    }

    fputc('A',fp); // character A is written to the file1.txt
    fclose(fp);
    return 0;
}

Inside file1.txt

C Programming Language fputc Function in File Handling Example 1


Example No. 2

#include<stdio.h>
int main()
{
    FILE *fp;
    char ch[] = "Its Beyond Simple";
    int i=0;
    fp=fopen("D:\\C Programming\\file2.txt","w");
    if(fp==NULL)
    {
        printf("\n Unable to open the FILE");
        return 1;
    }
	
    while(ch[i]!='\0')
    {
        fputc(ch[i],fp);
        i++;
    }
    fclose(fp);
    return 0;
}

Inside file2.txt

C Programming Language fputc Function in File Handling Example 2
 

Leave a reply