Commit bf8bb279 by albrat

Update func.c

parent 6873eb04
Showing with 84 additions and 1 deletions
#include <stdio.h>
#include "header.h"
void load_autos(Auto *autos) {
FILE *fp = fopen("autos.txt", "r");
if (fp == NULL) {
printf("Error opening autos file\n");
return;
}
for (int i = 0; i < MAX_AUTOS; i++) {
fscanf(fp, "%s %s %s %d %s", autos[i].mark, autos[i].model, autos[i].license_plate, &autos[i].year, autos[i].engine_size);
}
fclose(fp);
}
void load_owners(Owner *owners) {
FILE *fp = fopen("owners.txt", "r");
if (fp == NULL) {
printf("Error opening owners file\n");
return;
}
for (int i = 0; i < MAX_OWNERS; i++) {
fscanf(fp, "%s %s", owners[i].id, owners[i].name);
}
fclose(fp);
}
void find_most_powerful_car(Auto *autos) {
int max_index = 0;
for (int i = 1; i < MAX_AUTOS; i++) {
if (autos[i].engine_size > autos[max_index].engine_size) {
max_index = i;
}
}
printf("Most powerful car: %s %s\n", autos[max_index].mark, autos[max_index].model);
}
void find_oldest_car(Auto *autos) {
int min_index = 0;
for (int i = 1; i < MAX_AUTOS; i++) {
if (autos[i].year < autos[min_index].year) {
min_index = i;
}
}
printf("Oldest car: %s %s\n", autos[min_index].mark, autos[min_index].model);
}
void find_newest_car(Auto *autos) {
int max_index = 0;
for (int i = 1; i < MAX_AUTOS; i++) {
if (autos[i].year > autos[max_index].year) {
max_index = i;
}
}
printf("Newest car: %s %s\n", autos[max_index].mark, autos[max_index].model);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment