Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Answer the following C program questions: (1) Describe a scenario that justifies

ID: 3579524 • Letter: A

Question


Answer the following C program questions:
(1) Describe a scenario that justifies the requirement to check the return value from fclose().
(2) Describe the four parameters to fread().
(3) Describe the second parameter to fopen().
(4) If a fopen() call returns the hexadecimal value 0x123456, what does that indicate?
(5) What is the name of the struct that is used to determine the creation date of c:windows?
(6) Write lines of code that would determine and display the creation date of c:windows?
(7) What is the minimum value of argc?
(8) If your program has one argument on the command line, what is the value of argc? Conceptually, describe what the values of argv[0], argv[1], and argv[2] are.
(9) When would you use two backslashes in a double-quoted string in your source code? Conversely, when would you use one backslash?
(10) Is it more appropriate to use one or two backslashes when specifying an argument on the command line?

Explanation / Answer

1 - A scenario could be where a user has opened up a file to input some values from the file using fopen now when the work of that file completes then the user will close the file using fclose() not the user must return a value from the fclose() because a return value will tell the user wether the file is closed and if it is closed successfully then 0 is returned and if not then EOF is returned this will help user to know that the file is successfully closed or not .

2- There are 4 parameters to the funcltion fread() ie. fread(void *ptr, size_t size, size_t nmemb, FILE *stream)

ptr- it is a pointer to the block of memory with a min. size of *nmemb bytes .

size - it is the size of each elements in bytes .

nmemb - it is the number of elements each of size bytes .

stream - pointer to a file object which points to input stream .

3 - the second parameter in fopen() is the mode

mode- it is a c string which tells the node in which file is opened .

there are many modes which are

r- opens a file in read mode . the file must exist .

w - in this a new file is created and if same name file already exists then erases the contents of the file and it is considerd as an empty file .

a - append mode. it helps a user append data at the end of the file . file is created if it does not exists .

r+ - opens a file to update both reading and writting

w+ - creates a file for reading and writting

a+ - opens a file for reading and appending .

4- if a fopen returns a hexadecimal value then it is considered as null because an fopen() must always return a pointer to a file .

7- the minimum value of argc is set to 1 because if we dont pass any argument then also the argc is 1 .

8 - if the program has only one argument then the value of argc is 2 . argv[0] is the name of the file and argv[1] will contain the pointer to the first argument and argv[2] will contain the argument to the second argument .