1. #include <stdio.h> 2. void main() { 3. FILE *fptr; 4. char name[20]; 5. int a
ID: 3771879 • Letter: 1
Question
1. #include <stdio.h>
2. void main() {
3. FILE *fptr;
4. char name[20];
5. int age;
6. float salary;
7. fptr = fopen("emp.rec", "XX");
8. if (fptr == NULL)
9. {
10. printf("XXXXXXXXXXX ");
11. return;
12. }
13. printf("Enter the name ");
14. scanf("%s", name);
15. fprintf(fptr, "Name = %s ", name);
16. printf("Enter the age ");
17. scanf("%d", &age);
18. fprintf(fptr, "Age = %d ", age);
19. printf("Enter the salary ");
20. scanf("%f", &salary);
21. fprintf(fptr, "Salary = %.2f ", salary);
22. rewind(XXXX);
23. fclose(fptr);
24. }
Based on the code above what should the “XX” on line 7 be replaced with?
What is the name of the file being opened?
What should the printf() on line 10 say instead of “XXXXXXXXXXXX” ?
a) “File is open” b) “Segmentation Fault” c) “File cannot be opened” d) none of these
What should the rewind() on line 22 say instead of “XXXX”?
a) beginning b) emp.rec c) nothing d) none of these
T / F A FILE pointer is exactly the same as any other pointer we have discussed.
The _________ indicator tells us that there is no more data to process in the file.
a) null terminator b) feof c) decimal point d) none of these
What does the fprintf() function require that the printf() function doesn’t?
a) file pointer b) % conversion specifier c) memory address d) none of these
Match the file opening mode on the right with the term on the left.
_______ Open an existing file for reading a) w
b) o
_______ Open or create a file for writing at the end of the file c) b
d) r
_______ Create a file for writing. If the file already exists discard the e) a
current contents
Explanation / Answer
Based on the code above what should the “XX” on line 7 be replaced with?
Ans: It is npothing but file open mode.Here data is writing into the file..So "XX" menas "w+"
What is the name of the file being opened?
Ans: The Name of the file is "emp.rec"
What should the printf() on line 10 say instead of “XXXXXXXXXXXX” ?
a) “File is open” b) “Segmentation Fault” c) “File cannot be opened” d) none of these
Ans: Option C ... Because here in if condition is checking the file is open or not.
What should the rewind() on line 22 say instead of “XXXX”?
a) beginning b) emp.rec c) nothing d) none of these
Ans: Option C..this rewind will keep the file pointer beginning of the file
T / F A FILE pointer is exactly the same as any other pointer we have discussed.
Ans: No
The _________ indicator tells us that there is no more data to process in the file.
a) null terminator b) feof c) decimal point d) none of these
Ans: Option B..I.e feof()
What does the fprintf() function require that the printf() function doesn’t?
a) file pointer b) % conversion specifier c) memory address d) none of these
Ans: Option A.. I.e file pointer
Match the file opening mode on the right with the term on the left.
____d__ Open an existing file for reading a) w
b) o
___a____ Open or create a file for writing at the end of the file c) b
d) r
___w____ Create a file for writing. If the file already exists discard the e) a
current contents
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.