Valid CLA-11-03 Dumps shared by ExamDiscuss.com for Helping Passing CLA-11-03 Exam! ExamDiscuss.com now offer the newest CLA-11-03 exam dumps, the ExamDiscuss.com CLA-11-03 exam questions have been updated and answers have been corrected get the newest ExamDiscuss.com CLA-11-03 dumps with Test Engine here:
Assume that we can open a file called "file1". What happens when you try to compile and run the following program? #include <stdio.h> int main (void) { FILE *f; int i; f = fopen("file1","wb"); fputs("545454",f); fclose (f); f = fopen("file1","rt"); fscanf(f,"%d ", &i); fclose (f) ; printf("%d",i); return 0; } Choose the right answer:
Correct Answer: A
The program outputs 545454 because the fputs function writes the string "545454" to the file "file1" in binary mode, and the fscanf function reads the string as an integer from the file in text mode. The binary mode and the text mode are different ways of interpreting the data in a file. In binary mode, the data is stored as a sequence of bytes, and no translation is performed. In text mode, the data is stored as a sequence of characters, and some characters may be translated depending on the plat-form. For example, the newline character may be translated to a carriage return and a line feed on Windows, or just a line feed on Linux. The fopen function takes a mode argument that specifies whether the file should be opened in binary or text mode. The mode "wb" means write binary, and the mode "rt" means read text. When the fputs function writes the string "545454" to the file in binary mode, it writes the ASCII val-ues of each character as a byte. The ASCII value of '5' is 53, and the ASCII value of '4' is 52. There-fore, the file contains the following bytes: 53 53 53 52 52 52. When the fscanf function reads the file in text mode, it interprets the bytes as characters and converts them to an integer using the %d format specifier. The %d format specifier expects a decimal integer, which is a number com-posed of digits from 0 to 9. Since the file contains only digits, the fscanf function successfully con-verts the string "545454" to an integer with the same value. The printf function then prints the value of i as a decimal integer using the %d format specifier. References = CLA - C Certified Associate Programmer Certification, C Essentials 2 - (Intermediate), C File I/O, ASCII Table