programming in C language NOTE: For ALL of the problems below, NO CREDIT WILL BE
ID: 3715523 • Letter: P
Question
programming in C language
NOTE: For ALL of the problems below, NO CREDIT WILL BE AWARDED UNLESS EVERY STEP IS SHOWN AND THE 6. (40 Pts) Assume that you h of the employees of a college. The file is formatted with each line department they work in followed by the last name of the employee and the year For example, the file might look like this: ave been given a file called "employees.txt" that contains a record of all providing the initials of the they were hired. ENG POE 2009 CS MEYER 2005 ENG MILLER 1964 PSY GONZALEZ 2001 ENG PENCIU 2017 (10 Pts) In the space below, write the code for a structure that might be suitable for storing this information. a. erteg of the struct ,,r? 7-u CRoted ln (.tt A. oadporExplanation / Answer
#include<stdio.h>
struct employee{
char *dep;
char *lname;
int year;
}emp[100];
int main(){
FILE *fp;
char depInit[10], lnm[20]; // Assumign initials of dept will have max 10 chars and lname will have max 20 chars
int yr;
int i=0;
fp = fopen("employees.txt", "r");
if (fp == NULL){
printf("Could not open file");
return 1;
}
while(fscanf(fp, "%s %s %d", depInit, lnm, &yr) != EOF){
emp[i].dep = depInit;
emp[i].lname = lnm;
emp[i].year = yr;
i++;
}
char inp[10];
printf("Enter initials of department ");
scanf("%s", inp);
char *in = inp;
printf("NAME YEAR ");
for(int j=0; j<i; j++){
if(emp[j].dep = *in){
printf("%s %d", emp[j].lname, emp[j].year);
}
}
fclose(fp);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.