CSE101Lec39File1.ppt - CSE101-lec#39 \u2022 File handling \u00a9LPU CSE101 C Programming Outline \u2022 \u2022 \u2022 \u2022 \u2022 Introduction Description of FILE pointer

CSE101Lec39File1.ppt - CSE101-lec#39 • File handling...

This preview shows page 1 - 9 out of 38 pages.

©LPU CSE101 C Programming CSE101-lec#39 File handling
Image of page 1
©LPU CSE101 C Programming Outline Introduction Description of FILE pointer Categories of files Text and binary files Creating a Sequential Access File
Image of page 2
©LPU CSE101 C Programming Introduction Storage of data in variables and arrays is temporary such data is lost when a program terminates. Files are used for permanent retention of data. Computers store files on secondary storage devices, especially disk storage devices. Data files Can be created, updated, and processed by C programs Are used for permanent storage of large amounts of data
Image of page 3
©LPU CSE101 C Programming Categories of File Sequential-access files: In this if we want to read the last record of file then we need to read all the records before that record. It means if we want to read 10 th record then the first 9 records should be read sequentially for reaching to the 10 th record. Random-access files: In this data can be read and modified randomly. If we want to read the last record of the file, we can read it directly. It takes less time as compared as sequential file.
Image of page 4
©LPU CSE101 C Programming Types of files Text files: Text files are human readable files. They are universal and can be edited with many different programs such as NOTEPAD. contains ASCII codes only. they can only read or write data one character at a time that is sequentially. Binary files: Binary files are not human readable. They contain information encoded into the numbers which make up the file which are ultimately turned into ones and zeros, thus the name “binary.” Binary files can be either processed sequentially or randomly.
Image of page 5
©LPU CSE101 C Programming File pointer Before using a file in a program, we must open it, which establishes a link between the program and the file. A file pointer must be defined as:- FILE *fPtr ; structure file pointer where FILE is the Structure which is included in the header file, stdio.h and fPtr is declared as a pointer which contains the address of a file which is to be read.
Image of page 6
©LPU CSE101 C Programming Creating a Sequential Access File C imposes no structure on a file notions such as a record of a file do not exist as part of the C language Programmer must provide file structure Creating a File FILE *fPtr; Creates a FILE pointer called fPtr fPtr = fopen (“clients.txt", “w”); Function fopen returns a FILE pointer to file specified Takes two arguments – file to open and file open mode
Image of page 7
©LPU CSE101 C Programming fopen() fopen is a function which contains two arguments:- 1. File name to open 2. Mode in which we want to open the file.
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 38 pages?

  • Fall '14
  • gauravtak
  • File Handling, Computer file

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