Table of Contents
show
Sends formatted output to a stream.
Syntax
fprintf
int fprintf(FILE *stream, const char *format, …)
Parameters
stream − This is the pointer to a FILE object that identifies the stream.
format − This is the C string that contains the text to be written to the stream.
Return Value
If successful, the total number of characters written is returned otherwise, a negative number is returned.
Program: Send data from file using fprintf
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n;
FILE *fptr;
fptr=fopen("sample1.txt","w");
if(fptr==NULL)
{
printf("Cannot Open File!");
exit(1);
}
printf("Enter a Number: ");
scanf("%d",&n);
fprintf(fptr,"%d",n);
fclose(fptr);
printf("File Written Successfully !!");
}
Output
Views: 0