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 fprintf

C Syntax

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

Sample - C Code

void main()
    FILE *fp;
    fp = fopen("sample.txt","w");   // Open File in Write Mode
    fprintf(fp,"Welcome To Wikitechy");

C Code - Explanation :

  1. Here in this statement we create a file pointer “fp”.
  2. Here in this statement we open the text file using “fopen” function in writing mode.
  3. In this statement we write the content in the text file using fprintf function.

Sample Output - Programming Examples

  1. 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 .


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);



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

View More Quick Examples

Related Searches to C fprintf