Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Introduction [cont'd]
Input Output Functions [cont'd]
Structures and Unions [cont'd]
# Preprocessor [cont'd]
fprintf() in Files of Programming in C
1453 Views
fprintf() 
fprintf() - It is used to write multiple data's to a file.
Syntax 
fprintf(file_pointer_variable,datatype modes,value1,value2,value3. . .value n);
Program
	#include
	void main(){
	   FILE *fp;
	   int i;
	   int product_no;
	   char product_name[30];
	   fp = fopen("RECORD.txt","w");
	   for (i=0;i<5;i++){
	       printf("Enter the product no : ");
	       scanf("%d",&product_no);
	       printf("Enter the product name : ");
	       scanf("%s",&product_name);
	       fprintf(fp,"%d %s",product_no,product_name);
	   }
	   fclose(fp);
	}
Output 
Enter the product no : 101
Enter the product name : Hamam
Enter the product no : 102
Enter the product name : Liril
Enter the product no : 103
Enter the product name : Himalaya
Enter the product no : 104
Enter the product name : Colgate
Enter the product no : 105
Enter the product name : Lux

101 : Hamam
102 : Liril
103 : Himalaya
104 : Colgate
105 : Lux
Next Topics
Next lessons of current book.
# Preprocessor of Programming in C
Previous Topics
Previous lessons of current book.
Best Lessons of "Programming in C"
Top lessons which are viewed more times.
Structures and Unions of Programming in C
Input Output Functions of Programming in C
Structures and Unions of Programming in C
Sub Lessons
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details