Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. File Processing
  5. File Processing Operation...
  6. Output to file stream

Output to file stream

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

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments