Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

The fprintf() function

Syntax

fprintf(FILE *fpt, const char *format [arg1, arg2, …, argN])

This function is used to write/print data into the file.

Example

#include<stdio.h>
int main()
{
    FILE *fp;
    int emp_id_no = 7;
    char emp_name[50] = "JOHN";
	
    fp=fopen("D:\\C Programming\\file5.txt","w");
	
    if(fp==NULL)
    {
        printf("\n Unable to open the file");
        return 1;
    }
	
    fprintf(fp,"Employee ID of %s is %d",emp_name,emp_id_no);
    fclose(fp);
	
    return 0;
}

Inside file5.txt

C Programming Language fprintf Function in File Handling Example
 

Leave a reply