Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct employee {
- char name[128];
- float salary;
- };
- typedef struct employee Employee;
- float total_salary(Employee all[], int len);
- int main() {
- int num=3,i,j=0;
- Employee *all;
- FILE *file;
- file=fopen("employee.bin","r");
- i=0;
- all = (struct Employee *) malloc(sizeof(Employee)*3) ;
- while(!feof(file)){
- fscanf(file,"%c",&(*all).name[i]);
- printf("%c",((*all).name[i]));
- if((*all).name[i]==':'){
- fscanf(file,"%f",&(*(all+j)).salary);
- printf("%.2f",(*(all+j)).salary);
- j++;
- }
- i++;
- }
- printf("\n=%.1f\n", total_salary(all, num));
- fclose(file);
- return 0;
- }
- float total_salary(Employee all[], int len){
- int i=0;
- float sum;
- while(i<len){
- sum += (*(all+i)).salary;
- i++;
- }
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement