What does the following statement do? FILE *fp = fopen("employee.dat", "a");
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "Open a file named employee.dat to append data to the end of the file. If the file exists, the address of the file is assigned to the file pointer fp. If the file does not exist, a new file named employee.dat will be created and its address will be assigned to fp.". Chế độ nối của fopen giữ nguyên nội dung cũ và đặt mọi lần ghi xuống cuối tệp, còn tệp chưa có thì thư viện tạo mới; giá trị trả về là con trỏ tới cấu trúc mô tả dòng tệp, hoặc con trỏ rỗng khi mở thất bại. Mô tả "Create a file named employee.dat." nói như thể luôn tạo tệp mới, bỏ mất trường hợp tệp đã tồn tại và bỏ luôn ý nghĩa ghi nối. Mô tả "Open a file named employee.dat to read data." ứng với chế độ đọc, và chế độ đó còn trả về con trỏ rỗng khi tệp không tồn tại chứ không tạo tệp. Mô tả "all existing data will be overwritten" tự mâu thuẫn với việc nối thêm: xoá sạch nội dung cũ là hành vi của chế độ ghi mới.
Cùng phần 9
What is the purpose of "rb" in fopen() function used below in the code?
FILE *fp;
fp = fopen("demo.txt", "rb");Có lời giảiCâu hỏiWhat is the main difference between opening a file with mode "a+" and mode "w+" in C?Có lời giảiCâu hỏiWhat function is used to send formatted output to a file?Có lời giảiCâu hỏiCả 20 câu của chủ đề20 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây