{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SFTW120-LectureNotes-12 - SFTW120 Programming Science...

Info icon This 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 square6 Data can be stored on the computer s disk as a file square6 A file is a named collection of bytes square6 Two types of files exist: box2 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’ ) box2 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 )
Image of page 1

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

View Full Document Right Arrow Icon
2 SFTW120 - Programming Science 3 Lecture Notes 12 Text files square6 Example of a text file: This is a text file! <newline> It has two lines. <newline><eof> square6 This file has two lines of text, with a total of 40 characters (including two newline characters and one eof character) square6 Each character in the file is represented by its character code, e.g. by its ASCII code: box2 “This” is represented by the codes 84, 104, 105, 115 box2 <newline> is represented by the code 10 box2 <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 ‘.’
Image of page 2
3 SFTW120 - Programming Science 5 Lecture Notes 12 Streams square6 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> square6 A stream is a continuous sequence of character codes square6 Two main types of streams: box2 Input stream : a stream that is a data source , i.e. from which characters are read into a program box2 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 square6 C programs always have access to three standard streams: box2 stdin : the standard input stream; this stream is connected to the keyboard box2 stdout : the standard output stream; this stream is connected to the screen and prints normal output box2 stderr : the standard error stream; this stream is connected to the screen and prints error messages square6 The functions scanf and printf are connected to the standard input and output streams: box2 scanf reads from stdin box2 printf writes to stdout
Image of page 3

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

View Full Document Right Arrow Icon
4 SFTW120 - Programming Science 7 Lecture Notes 12 Special characters square6 A character stream can contain normal (printable) text characters, and also special (non-visible) characters square6
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern