Advertisement
Guest User

XO-01

a guest
Sep 21st, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include <stdlib.h>
  4. #include<malloc.h>
  5. struct employee {
  6.   char name[128];
  7.   float salary;
  8. };
  9.  
  10. typedef struct employee Employee;
  11.  
  12. int main(){
  13.     int n = 3;
  14.     Employee i[3];
  15.     strcpy(i[0].name, "Jonh Doe");
  16.     i[0].salary = 3000.0;
  17.     strcpy(i[1].name, "Mark Ken");
  18.     i[1].salary = 2300.0;
  19.     strcpy(i[2].name, "Sucy Merc");
  20.     i[2].salary = 2000.0;
  21.     FILE *fp = fopen("D:\\employee.bin","w+b");
  22.     fwrite(&n, sizeof(int),1,fp);
  23.     fwrite(i, sizeof(Employee), 3, fp);
  24.     fclose(fp);
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement