~learax/csci112-2021-william-culhane

5af494f175c09a83cf7005451f8b2c180ab5a05e — William Culhane 3 years ago 2a0d587
program2: Complete main functionality
1 files changed, 37 insertions(+), 3 deletions(-)

M programs/program2/program2.c
M programs/program2/program2.c => programs/program2/program2.c +37 -3
@@ 58,8 58,8 @@ int parse_csv(const char filename[], course_t courses[MAX_COURSES]) {
}

void print_course(course_t course) {
  printf("%-10s %35s\n", course.code, course.name);
  printf("%-2i %-7s %-8s %25s\n\n", course.seats_open, course.weekdays,
  printf("%-10s %36s\n", course.code, course.name);
  printf("%-3i %-7s %-8s %25s\n\n", course.seats_open, course.weekdays,
         course.time, course.professor);
}



@@ 70,7 70,7 @@ void print_courses(unsigned int max_course, course_t courses[MAX_COURSES]) {
}

void search_course_code(unsigned int max_course, course_t courses[MAX_COURSES],
                        char scode[]) {
                        char scode[10]) {
  for (unsigned int i = 0; i < max_course; i++) {
    if (strcmp(courses[i].code, scode) == 0) {
      print_course(courses[i]);


@@ 78,6 78,24 @@ void search_course_code(unsigned int max_course, course_t courses[MAX_COURSES],
  }
}

void search_course_days(unsigned int max_course, course_t courses[MAX_COURSES],
                        char sdays[8]) {
  for (unsigned int i = 0; i < max_course; i++) {
    if (strcmp(courses[i].weekdays, sdays) == 0) {
      print_course(courses[i]);
    }
  }
}

void search_course_upper_bound_seats(unsigned int max_course, course_t courses[MAX_COURSES],
                        unsigned int sseats) {
  for (unsigned int i = 0; i < max_course; i++) {
    if (courses[i].seats_total <= sseats) {
      print_course(courses[i]);
    }
  }
}

int main(void) {
  course_t courses[MAX_COURSES];



@@ 107,6 125,22 @@ int main(void) {
      search_course_code(max_course, courses, scode);
      break;
    }
    case 'd': {
      char sdays[8];
      printf("Weekday combo: ");
      scanf(" %[^\n]", sdays);
      printf("\n");
      search_course_days(max_course, courses, sdays);
      break;
    }
    case 's': {
      unsigned int sseats;
      printf("Max seats: ");
      scanf(" %u", &sseats);
      printf("\n");
      search_course_upper_bound_seats(max_course, courses, sseats);
      break;
    }
    }

    choice = getchar();