codescracker


c

C fprintf()



« Previous Function Next Function »


fprintf()

The fprintf() is used to output the values of the arguments that make up the argument list as specified in the format string to the stream pointed to by stream.

fprintf() Syntax

#include<stdio.h>
int fprintf(FILE *stream, const char *format, ...);

The return value is the number of characters actually printed. If an error occurs then a negative number is returned.

fprintf() Example

Following c program creates a file named demo.txt and writes this is a demo file 20 10.20 into the file using fprintf() function to format the data:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
	clrscr();
	FILE *fp;
	fp=fopen("demo.txt", "wb");
	if(fp==NULL)
	{
		printf("Error in opening the file..!!\n");
		printf("Press any key to exit..\n");
		getch();
		exit(1);
	}
	fprintf(fp, "this is a demo file %d %f", 20, 10.20);
	fclose(fp);
	getch();
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test