Ok I have the majority of this program complete. I've gotten the program to print all of the names along with all of the salaries.
One question...how would I go about calculating who has the largest salary and getting the program to print only that?
Code:
#include <stdio.h>
#include <string.h>
typedef struct{
char name[31];
float wages;
} people_t;
int main() {
people_t people[30];
int i = 0;
char person[31];
FILE *inFile1;
FILE *inFile2;
inFile1 = fopen("people.txt", "r");
if(inFile1 == NULL) {
printf("%s failed. Exiting program\n", "people.txt");
exit(1);
}
inFile2 = fopen("wages.txt", "r");
if(inFile2 == NULL) {
printf("%s failed. Exiting program\n", "wages.txt");
exit(2);
}
fscanf(inFile1, "%s", &person);
while( i < 20 && !feof(inFile1)){
strcpy(people[i].name, person);
fscanf(inFile1, "%s", &person);
i++;
}
i = 0;
fscanf(inFile2, "%f", &people[i].wages);
while( i < 20 && !feof(inFile2)){
i++;
fscanf(inFile2, "%f", &people[i].wages);
}
fclose(inFile1);
fclose(inFile2);
i = 0;
printf("\t Name \t \t \t Wages\n");
while (i < 20) {
printf("\t %s \t \t %.2f\n", people[i].name, people[i].wages);
i++;
}
return 0;
}