~learax/csci112-2021-william-culhane

2a0d587ed2290159b7aefcf24a5b3ad1ff842634 — William Culhane 3 years ago 268f6be
program2: Add course search functionality
1 files changed, 21 insertions(+), 2 deletions(-)

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

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


@@ 69,6 69,15 @@ 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[]) {
  for (unsigned int i = 0; i < max_course; i++) {
    if (strcmp(courses[i].code, scode) == 0) {
      print_course(courses[i]);
    }
  }
}

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



@@ 85,10 94,20 @@ int main(void) {
           "q - quit\n");

    switch (choice) {
    case 'a':
    case 'a': {
      printf("\n");
      print_courses(max_course, courses);
      break;
    }
    case 'n': {
      char scode[10];
      printf("Course code: ");
      scanf(" %[^\n]", scode);
      printf("\n");
      search_course_code(max_course, courses, scode);
      break;
    }
    }

    choice = getchar();
  } while (choice != 'q');