SFTW120-LectureNotes-12

SFTW120-LectureNotes - SFTW120 Programming Science Lecture Notes 12 C File processing(Textbook Chapter 12 Robert P Biuk-Aghai Files Data can be

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 SFTW120 Programming Science Lecture Notes 12: C: File processing (Textbook Chapter 12) © Robert P. Biuk-Aghai SFTW120 - Programming Science 2 Lecture Notes 12 Files s Data can be stored on the computer s disk as a file s A file is a named collection of bytes s Two types of files exist: b Text files : the contents of the file are all characters; all different data types are represented using characters (e.g. the integer 123 is represented using three bytes as the three characters ‘1’ , ‘2’ , and ‘3’ ) b Binary files : the contents of the file are binary numbers; all different data types are represented using numbers; this is the same as the internal representation of data inside the computer (e.g. the integer 123 is represented using one byte as the binary number 01111011 )
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 SFTW120 - Programming Science 3 Lecture Notes 12 Text files s Example of a text file: This is a text file! <newline> It has two lines. <newline><eof> s This file has two lines of text, with a total of 40 characters (including two newline characters and one eof character) s Each character in the file is represented by its character code, e.g. by its ASCII code: b “This” is represented by the codes 84, 104, 105, 115 b <newline> is represented by the code 10 b <eof> is represented by the special code 1 (this is not an ASCII character) SFTW120 - Programming Science 4 Lecture Notes 12 Internal representation of text files Internal representation of the text file: This is a text file! <newline> It has two lines. <newline><eof> ASCII codes (in hexadecimal) Corresponding text 54686973 20697320 61207465 78742066 This is a text f 696c6521 0a497420 68617320 74776f20 ile!.It has two 6c696e65 732e0a lines. . Note : non-printing characters (like newline) are shown as ‘.’
Background image of page 2
3 SFTW120 - Programming Science 5 Lecture Notes 12 Streams s Internally, a text file is not made up of separate lines, but of one continuous stream of characters: This is a text file! <newline> It has two lines. <newline><eof> s A stream is a continuous sequence of character codes s Two main types of streams: b Input stream : a stream that is a data source , i.e. from which characters are read into a program b Output stream : a stream that is a data destination , i.e. to which characters are written from a program SFTW120 - Programming Science 6 Lecture Notes 12 Standard streams s C programs always have access to three standard streams: b stdin : the standard input stream; this stream is connected to the keyboard b stdout : the standard output stream; this stream is connected to the screen and prints normal output b stderr : the standard error stream; this stream is connected to the screen and prints error messages s The functions scanf and printf are connected to the standard input and output streams: b scanf reads from stdin b printf writes to stdout
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 SFTW120 - Programming Science 7 Lecture Notes 12 Special characters s A character stream can contain normal
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/04/2011 for the course SFST 120 taught by Professor Dr.robert during the Spring '11 term at University of Macau.

Page1 / 16

SFTW120-LectureNotes - SFTW120 Programming Science Lecture Notes 12 C File processing(Textbook Chapter 12 Robert P Biuk-Aghai Files Data can be

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online