C Program to Print the Age and Name of Employee.

Write a C program to print the age and name of employee using fprintf() and fscanf() operations.

So far we have seen many programs. This is not enough if we need to write characters, strings, and integers in one single file, in that case, we use fprintf() function. The fprintf() function is used to write set of characters into the file. It sends formatted output to a stream.
The fscanf() function is similar to scanf() function except for the first argument which is a file pointer that specifies the file to be read.

C Programming Code:


struct emp
   char name[10];
   int age;

void main()
   struct emp e;
   FILE *p,*q;
   p = fopen(“one.txt”, “a”);
   q = fopen(“one.txt”, “r”);
   printf(“Enter Name and Age:”);
   scanf(“%s %d”, e.name, &e.age);
   fprintf(p,”%s %d”, e.name, e.age);
       fscanf(q,”%s %d”, e.name, e.age);
       printf(“%s %d”, e.name, e.age);