C - fprintf
File Operations in Tamil

Learn C - C tutorial - C fprintf - C examples - C programs
C - fprintf() - Definition and Usage
- In C – Programming, the fprintf function is used to pass the argument according to the specified format in terms of the file indicated format.

C Syntax
int fprintf(FILE *stream, const char *format, ...)

Sample - C Code
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
fp = fopen("sample.txt","w"); // Open File in Write Mode
fprintf(fp,"Welcome To Wikitechy");
}
C Code - Explanation :

- Here in this statement we create a file pointer “fp”.
- Here in this statement we open the text file using “fopen” function in writing mode.
- In this statement we write the content in the text file using fprintf function.
Sample Output - Programming Examples

- Here in this output, the entered statement “Welcome To Wikitechy” from the program using fprintf function were written in the sample.txt file which will be stored in the BIN folder of C .
Example
#include<stdio.h>
struct emp
{
char name[10];
int age;
};
void main()
{
struct emp e;
FILE *p;
p = fopen("one.txt", "a");
printf("Enter Name and Age:");
scanf("%s %d", e.name, &e.age);
fprintf(p,"%s %d", e.name, e.age);
fclose(p);
}
Output

Learn C - C tutorial - C fprintf - C examples - C programs