Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q12 You have been assigned the following seemingly working C code, which processes files controlling the behaviour of a system. You observe that, after obtaining

image text in transcribed
Q12 You have been assigned the following seemingly working C code, which processes files controlling the behaviour of a system. You observe that, after obtaining several ERR_MALFORMED errors, subsequent calls to fopen fail due to too many files being open: int process_file(char *name) { FILE *p = fopen(name, "r"); if (p = NULL) return ERR_NOTFOUND; while (...) { ... if (...) return ERR_MALFORMED; process_one_option(); ... } fclose(p); return SUCCESS; } (i) Explain how to fix the program using facilities in C. (2 marks) (ii) Nowysuppose the function above was part of a system written in C++ (but still using the C file- processing commands such as fopen and fclose), and that process_one_option() might raise one or more exceptions. Using a class with a destructor, show how to fix the "too many files open" bug above.? (6 Marks) ni Q12 You have been assigned the following seemingly working C code, which processes files controlling the behaviour of a system. You observe that, after obtaining several ERR_MALFORMED errors, subsequent calls to fopen fail due to too many files being open: int process_file(char *name) { FILE *p = fopen(name, "r"); if (p = NULL) return ERR_NOTFOUND; while (...) { ... if (...) return ERR_MALFORMED; process_one_option(); ... } fclose(p); return SUCCESS; } (i) Explain how to fix the program using facilities in C. (2 marks) (ii) Nowysuppose the function above was part of a system written in C++ (but still using the C file- processing commands such as fopen and fclose), and that process_one_option() might raise one or more exceptions. Using a class with a destructor, show how to fix the "too many files open" bug above.? (6 Marks) ni

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

ISBN: 0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

b. Will there be one assigned leader?

Answered: 1 week ago

Question

Do you currently have a team agreement?

Answered: 1 week ago