TAILIEUCHUNG - Lecture Introduction to computer and programming - Lecture No 28

The contents of this chapter include all of the following: Assembly is the component of the CLR, assembly identity made of four components, application typically made of several assemblies. | CSC103: Introduction to Computer and Programming Lecture No 28 Previous lecture Introduction to File File operations Reading from file (character by character) Writing in file (character by character) Today’s lecture outline File opening mode String (line) I/O in Files Reading a string Writing a string Reading and writing numbers in file Text vs. binary file Reading and writing in binary file File opening mode "r+" : Reading, writing, modifying content of file, if file does not exist it returns null "w+" : Reading, writing, modifying content of file, if file does not exits a new file is created "a+" : Reading, adding new contents at the end of file, cannot modify existing contents. if file does not exits a new file is created Writing string in a file fputs ( s, fp ) ; fputs( ) function writes the contents of the array pointer by pointer s to the file pointed by pointer fp Enter a few lines of text Hello world Hello world C programming C programming Go to program Reading string from a file fgets ( s, 79, fp ) ; This function read 79 bytes (character) from file pointed by pointer fp and write in the memory address s. s is base address of a character array This function returns NULL if no record is available to read Go to program New line character If we write the following on file using fputs Actual number of character in file are 24 But the size of file will be 26 Reason : fputs( ) converts the \n to \r\n combination Hello world programming Cont. If we read the same line back using fgets( ) the reverse conversion happens. Thus when we write the first line of the poem and a “\n” using two calls to fputs( ), what gets written to the file is Baa baa black sheep have you any wool \r\n Go to program Writing integer and float in file Until now we have seen following functions fgetc(fp); fputc(ch, fp); fgets(s, 79, fp); fputs(s, fp) C provide functions to write integer and float values in file fprintf - use to print (write) on file fscanf - use to scan (read) a file .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.