@@ 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');