Question: This function will read a list of courses from the file specified by the first argument. The courses should be stored in the g-course.array; the

 This function will read a list of courses from the file
specified by the first argument. The courses should be stored in the
g-course.array; the first one stored at offset zero and so on. Sometimes,
the course description may be larger than the space available to store
them in the course.t structs. In such cases, you should truncate the

This function will read a list of courses from the file specified by the first argument. The courses should be stored in the g-course.array; the first one stored at offset zero and so on. Sometimes, the course description may be larger than the space available to store them in the course.t structs. In such cases, you should truncate the strings appropriately, and continue to read from the file. To facilitate this, you may use large, temporary buffers to read the strings into. These buffers should be of size MAX BUFF LEN, and if an input string would exceed the bounds of any such buffer, you should return BAD RECORD. If the file contains too many courses to be stored, you should return TOO MUCH DATA. This function should assert that the argument is not NULL. If any other errors occur, it should return an appropriate error code from the list of error codes below. Otherwise, the function should return the number of courses read from the input file. Write the assertions separately to avoid memory errors. Don't forget to update g-course_count. int find prerequisites(char *, enum course_type_t); This function should search through all the prerequisites of the course specified by the first argument and return the largest credit hours with the type given by the second argument. Page 2 Homework 6 CS240 - Spring 2023 The first argument will be a prefix of the course name as it is stored in g-course-array. The prerequisite course must have the same type as the one specified by the second argument. Since there can be more than one prerequisite of a course, if two or more courses have the same type as the second argument, return the maximum credit hours out of those courses. Return 0 if a course does not have any prerequisites of the specified type. Return NOT FOUND if the course or one of its prerequisites cannot be found in g-course-array. Return NO COURSES if g-course_count is 0 . The function should assert that the first argument is not NULL and the second argument is a valid course type. Write the assertions separately to avoid memory errors. 4.2 Input Files The input file will contain records of the following format: course_name |?prerequisite1?prerequisite2 ...?prerequisiteN | course_typel credit_hours A course can have [0 - MAX PREQ] prerequisites, and each prerequisite is proceeded by a questionmark (?). 4.4 Error Codes - NON READABLE FILE: the file cannot be opened for read access - BAD RECORD: a record was read from a file that didn't make sense or was incomplete - TOO MUCH DATA: the file contained more than MAX COURSES - NO COURSES: The file does not have any courses, or there are no courses in g-course array - NOT FOUND: A course required to complete the request cannot be found in g-course-array The structure should look like this (we combine it with a typedef so that we can refer to it with one name): typedef struct course \{ char course_name[MAX_NAME_LEN]; char prerequisites [MAX_PREREQ] [MAX_NAME_LEN]; enum course_type_t course_type; int credit_hours; \} course_t; This function will read a list of courses from the file specified by the first argument. The courses should be stored in the g-course.array; the first one stored at offset zero and so on. Sometimes, the course description may be larger than the space available to store them in the course.t structs. In such cases, you should truncate the strings appropriately, and continue to read from the file. To facilitate this, you may use large, temporary buffers to read the strings into. These buffers should be of size MAX BUFF LEN, and if an input string would exceed the bounds of any such buffer, you should return BAD RECORD. If the file contains too many courses to be stored, you should return TOO MUCH DATA. This function should assert that the argument is not NULL. If any other errors occur, it should return an appropriate error code from the list of error codes below. Otherwise, the function should return the number of courses read from the input file. Write the assertions separately to avoid memory errors. Don't forget to update g-course_count. int find prerequisites(char *, enum course_type_t); This function should search through all the prerequisites of the course specified by the first argument and return the largest credit hours with the type given by the second argument. Page 2 Homework 6 CS240 - Spring 2023 The first argument will be a prefix of the course name as it is stored in g-course-array. The prerequisite course must have the same type as the one specified by the second argument. Since there can be more than one prerequisite of a course, if two or more courses have the same type as the second argument, return the maximum credit hours out of those courses. Return 0 if a course does not have any prerequisites of the specified type. Return NOT FOUND if the course or one of its prerequisites cannot be found in g-course-array. Return NO COURSES if g-course_count is 0 . The function should assert that the first argument is not NULL and the second argument is a valid course type. Write the assertions separately to avoid memory errors. 4.2 Input Files The input file will contain records of the following format: course_name |?prerequisite1?prerequisite2 ...?prerequisiteN | course_typel credit_hours A course can have [0 - MAX PREQ] prerequisites, and each prerequisite is proceeded by a questionmark (?). 4.4 Error Codes - NON READABLE FILE: the file cannot be opened for read access - BAD RECORD: a record was read from a file that didn't make sense or was incomplete - TOO MUCH DATA: the file contained more than MAX COURSES - NO COURSES: The file does not have any courses, or there are no courses in g-course array - NOT FOUND: A course required to complete the request cannot be found in g-course-array The structure should look like this (we combine it with a typedef so that we can refer to it with one name): typedef struct course \{ char course_name[MAX_NAME_LEN]; char prerequisites [MAX_PREREQ] [MAX_NAME_LEN]; enum course_type_t course_type; int credit_hours; \} course_t

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!