Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C Program Just opening a file, catching the return value of fopen in a variable, use the latter in the assertion for probe() and then
C Program
Just opening a file, catching the return value of fopen in a variable, use the latter in the assertion for probe() and then use macro debug() to print out a message in case the opening of the file is working fine. And, you need to have a label error: at the end of main() so that the program flow can jump there in case there is a problem with opening the file. Make sure to put a return statement after the label that indicates an unsuccessful program run.
DO NOT FORGET TO SHOW A SCREEN SHOT OF ITS WORKING!
In this assignment, you will get some insights into debugging and functions macros. What to do Write a simple C program, which opens a file. As you know, this may either be successful or it may fail. In the case of the opening failing, I want you to use the macro "probe/A, ...)", which I have introduced in class, to handle the situation. By "handling the situation" I mean that you print out an error message that contains the file name, e.g. "Opening file XXx failed!" and then ump to a label "error:" that you have put at the very end of the function you are doing this in, most likely just main0 and returning with EXIT_FAILURE. On the other hand, if the file opening worked just fine, I ask you to use the macro that allows you to print out a debug message that will be displayed depending on whether you have the symbolic constant DEBUG defined or not. What to submit I ask you to submit the following: The well-commented source code of your program . One screen shot of the standard output showing the situation, when the file could be opened just fine. One screen shot of the standard output showing the situation, when the file could not be opened . One screen shot of the part of your code containing the (replaced) macro probe0, after the preprocessor touched it. I ask you to augment this screen shot as follows: using any graphics program of your choice, please underline the part of the macro replacement, that contains the message that you provided originally. Hint To finish this assignment successfully, you will need the debug macros file, which I introduced in class: dgb.h Remember that the value returned from fopen0 can be used to recognize, whether the function performed fine or ran into an error (e.g. the file to be opened is not there). This value you can use as the assertions probe0 needs to do its job. In this assignment, you will get some insights into debugging and functions macros. What to do Write a simple C program, which opens a file. As you know, this may either be successful or it may fail. In the case of the opening failing, I want you to use the macro "probe/A, ...)", which I have introduced in class, to handle the situation. By "handling the situation" I mean that you print out an error message that contains the file name, e.g. "Opening file XXx failed!" and then ump to a label "error:" that you have put at the very end of the function you are doing this in, most likely just main0 and returning with EXIT_FAILURE. On the other hand, if the file opening worked just fine, I ask you to use the macro that allows you to print out a debug message that will be displayed depending on whether you have the symbolic constant DEBUG defined or not. What to submit I ask you to submit the following: The well-commented source code of your program . One screen shot of the standard output showing the situation, when the file could be opened just fine. One screen shot of the standard output showing the situation, when the file could not be opened . One screen shot of the part of your code containing the (replaced) macro probe0, after the preprocessor touched it. I ask you to augment this screen shot as follows: using any graphics program of your choice, please underline the part of the macro replacement, that contains the message that you provided originally. Hint To finish this assignment successfully, you will need the debug macros file, which I introduced in class: dgb.h Remember that the value returned from fopen0 can be used to recognize, whether the function performed fine or ran into an error (e.g. the file to be opened is not there). This value you can use as the assertions probe0 needs to do its jobStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started