CSE115Lecture17FileProcessing - Lecture 17 File Processing CSE115 Computing Concepts Files and Streams C views a file as a sequential stream of bytes A

CSE115Lecture17FileProcessing - Lecture 17 File Processing...

This preview shows page 1 - 7 out of 20 pages.

Lecture 17 File Processing CSE115: Computing Concepts
Image of page 1
Files and Streams C views a file as a sequential stream of bytes. A file ends with EOF (end-of-file) marker When a file is opened, a stream is associated with a file. Streams provide communication channels between files and the programs. H E L L O W O R L . . . . . EOF
Image of page 2
Files and Streams In addition to providing access to a file, a stream can also be used to access devices. For example, when a program (any program) is executed, 3 streams are automatically opened: standard input ( stdin ) enable the program to read data from keyboard standard output ( stdout ) enable the program to print data on the screen standard error ( stderr ) enable program to print errors on the screen They are all manipulated using file pointers.
Image of page 3
Declaring a file The standard library <stdio.h> provides some of the file manipulation function. Declaring file: FILE *the_file; States that the_file is a pointer variable that points to a file structure If there is more than one file, each file needs to have its own FILE pointer.
Image of page 4
File operation: fopen() Before we can process a file, we must either open or create it. Syntax for fopen( ): file_pointer_name = fopen(file_name, OpenMode); The fopen() function takes 2 arguments: the file name and the file mode.
Image of page 5
File operation: fopen() Example: FILE *the_file; the_file = fopen("my_file.txt","r"); This statement will try to open a file called “my_file.txt”.
Image of page 6
Image of page 7

You've reached the end of your free preview.

Want to read all 20 pages?

  • Fall '11
  • Pointer, Standard streams, thefile

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

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes