C 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

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:

void main()
	FILE *fp;
	fp=fopen("demo.txt", "wb");
		printf("Error in opening the file..!!\n");
		printf("Press any key to exit..\n");
	fprintf(fp, "this is a demo file %d %f", 20, 10.20);

C Online Test

« Previous Function Next Function »

Like/Share Us on Facebook 😋