Skip to main content Accessibility help
×
Hostname: page-component-78c5997874-lj6df Total loading time: 0 Render date: 2024-11-08T05:19:11.356Z Has data issue: false hasContentIssue false

7 - File Operations

Published online by Cambridge University Press:  05 June 2012

Harley R. Myler
Affiliation:
Lamar University
Get access

Summary

Access to files allows a program to exploit the largest memory subsystem available to contemporary machines, that of the hard disk, CDROM, or tape drives. The file, regardless of which type of media that it resides on, can be thought of as a massive array of data. You can read from this data source, write to it, and create new instances and eliminate them from within your programs. Two primary modes of access to files are available: the low-level operations that work with bytes of data, and high-level operations that utilize data streams to store and retrieve the values of variables. We explore both methods in this chapter.

Low-Level File Operations

A file can be considered a document that has been stored and that will be accessed as a stream of bytes, such as depicted in Figure 7.1. Files are operating system (OS) resources, and requests must be made to the operating system for access to them. The operating system assigns a filename to a file, and the specifics of what characters are permitted in the name as well as the length are system-dependent. Typically, filenames have a prefix and suffix, and by now you have probably encountered this in your programming. The prefix describes the contents of the file, such as “myprog,” to describe a program that you are writing. The suffix indicates the type of file, such as “.c” for C source or “.for” for Fortran source, and so on.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 1998

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • File Operations
  • Harley R. Myler
  • Book: Fundamentals of Engineering Programming with C and Fortran
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139175029.008
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • File Operations
  • Harley R. Myler
  • Book: Fundamentals of Engineering Programming with C and Fortran
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139175029.008
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • File Operations
  • Harley R. Myler
  • Book: Fundamentals of Engineering Programming with C and Fortran
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139175029.008
Available formats
×