15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

264<br />

Storing Fixed Size Data in Random-Access Files<br />

The Portable Document Format (PDF)<br />

Although you can share plain text files among<br />

different computers, you always lose the <strong>for</strong>matting<br />

of that data. To avoid this problem,<br />

Adobe developed its own “universal” file<br />

<strong>for</strong>mat — the Portable Document Format (PDF).<br />

The idea behind PDF files is to allow people to<br />

create and distribute files that display data<br />

exactly the same no matter what computer they<br />

may use. So if you create a flyer or a newsletter,<br />

the appearance of your flyer or newsletter<br />

looks the same on a Macintosh computer as it<br />

does on a computer running a completely different<br />

operating system, such as Windows or<br />

Linux.<br />

PDF files have two drawbacks. First, you can’t<br />

edit them without special software, so PDF files<br />

are meant more <strong>for</strong> displaying in<strong>for</strong>mation than<br />

<strong>for</strong> letting you actually change that in<strong>for</strong>mation.<br />

That’s why many governments distribute documents<br />

and <strong>for</strong>ms as PDF files so people can see<br />

the in<strong>for</strong>mation, such as tax <strong>for</strong>ms, but they<br />

can’t change it.<br />

Second, you can’t view the contents of a PDF<br />

file unless you have a special PDF viewing or<br />

reader program, which Adobe gives away <strong>for</strong><br />

free. Un<strong>for</strong>tunately, if Adobe doesn’t make a<br />

PDF reader program <strong>for</strong> your operating system,<br />

you can’t read PDF files.<br />

Despite these drawbacks, PDF files are popular<br />

<strong>for</strong> sharing in<strong>for</strong>mation among different<br />

computers and operating systems while retaining<br />

the original appearance of a file, such as a<br />

word processor document. If you just want to<br />

share in<strong>for</strong>mation, PDF files are currently the<br />

most popular way to do so.<br />

Many Web sites can store in<strong>for</strong>mation on your computer in a cookie. A<br />

cookie is nothing more than a text file that stores your Web site settings,<br />

such as your username. That way if you visit that Web site again, the Web<br />

site retrieves the cookie off your computer and uses that in<strong>for</strong>mation to customize<br />

the Web page that you see.<br />

For programmers, the most common text file is the source code to any program<br />

whether that program is written in C++, Perl, Tcl, or Prolog.<br />

Storing Fixed Size Data in Random-Access Files<br />

One of the biggest problems with text files is that retrieving data requires<br />

reading the entire text file from beginning to end. In a large text file, this<br />

makes retrieving data clumsy and slow.<br />

Whereas text files act more like audiocassette tapes, random-access files are<br />

more like compact discs that allow you to skip right to the data you want to<br />

retrieve (which is why they’re random-access files).<br />

A random-access file organizes data in equal sized chunks called a record. A<br />

record defines what type of data to store, such as a first and last name, age,<br />

and phone number, as shown in Figure 8-1.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!