Answer to Question #304323 in C for mouli

Question #304323

The file named called EMPLOYEE.txt contains employee details such as employee number, name, designation and salary of employee. Write a program to create a file to store the details of employee (Use of structure and fwrite () & fread () functions).

Runtime Input :

101 xyz workshop 8500

102 nmo computer 6750

103 abc store 5890


1
Expert's answer
2022-03-02T01:16:39-0500
#include <stdio.h>

struct employee {
  int number;
  char *name;
  int designation;
}

void write(FILE *f, struct employee) {
  fwrite(&employee.number, sizeof(int), 1, f);
  fwrite(employee.name, sizeof(char) * strlen(employee.name), 1, f);
  fwrite(employee.designation, sizeof(int), 1, f);
}

int main() {
  FILE *f = fopen('EMPLOYEE.txt', 'rb');
  struct employee emp;
  emp.number = 1;
  emp.name = 'John';
  emp.designation = 3455;
  write(f, emp);
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS