Files are simply a long stream of binary bits of data. The use of files depends on what the file is made up of; more or less, each file is written with a sort of pattern to make it possible to read it again and write it again.
The most common form of file is the "Text" file. The text file is basically filled with binary values from the ASCII character set (see previous graphic for more details on that). The pattern for the average text file is that for one, it will not hold any data other than the first 127 bites of the ASCII table (yes, there are exceptions, but this is the "basic" text file), there will be "End of Line" markers that will tell programs when to stick in a carriage return, and then there might be an end of file marker.
In a moment of non sequiter theatre, lets point out that the "End of Line" marker is different based upon the operating system involved. In Windows, the end of line is marked with a "Carrage Return" plus a "Line Feed" character, where as many unix systems only use "Carriage Return." Knowing what your text file is made up of is important before you commit to one method or another.
The methods of reading these files are so common and so often used, that just about every compiler has ways to read them. "Getline()" method will read from the first of the file, to the end of line marker, and return what it finds. "Writeline()" will write out a text line and include the end of line marker automatically. "eof()" will test if the text file is at the end of the file.
If you would consider a text file like a paragraph made up of rows and columns. Each row and column has a letter that fits inside that paragraph. Consider this picture:
[{tab}][I][{space}][a][m][{space}][a][{carriage return}][{line feed}]
[s][i][m][p][l][e][{space}][t][e][x][t][{carriage return}][{line feed}]
[f][i][l][e][{end of file}]
As you read from the text file, a cursor is advancing through each column and row as you pull data out. Once it reaches the end, no more data can be pulled.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment