C

Saturday, 8 July 2017

Program to read name of a employee, employee number and salary from the keyboard and writes same to binary file

#include<stdio.h>
struct employee
{
          int eno,salary;
          char name[20];
}        
main()
{

          struct employee e;
          char ans;
          FILE *fp;
          fp=fopen("file9.out","wb");
          if(fp==NULL)
          {
                   printf("Error in file opening");
                   exit(0);
          }
          do
          {
                   printf("\nEmployee No.");
                   scanf("%d",&e.eno);
                   printf("\nName :");
                   scanf("%s",&e.name);
                   printf("\nSalary");
                   scanf("%d",&e.salary);
                   fwrite(&e,sizeof(e),1,fp);
                   printf("\nDo you want to add more records y/n");
                   ans=getch();
          }while(ans !='n');
          fclose(fp);

}

No comments:

Post a Comment

Write a program to draw a circle using mid-point circle drawing algorithm.

#include<iostream.h> #include<graphics.h> #include<conio.h> void drawcircle(int x0, int y0, int r) {         ...