lecture 14 lecture 14
play

Lecture 14 Lecture 14 2. B inary R epresentation What is a - PDF document

1. Introduction Lecture 14 Lecture 14 2. B inary R epresentation What is a file? 3. H ardw are and S oftw are 4. H igh Level Languages 5. S tandard input and output A file is data stored in secondary storage 6. Operators,


  1. 1. Introduction Lecture 14 Lecture 14 2. B inary R epresentation What is a file? 3. H ardw are and S oftw are 4. H igh Level Languages 5. S tandard input and output • A file is data stored in secondary storage 6. Operators, expression and statem ents • This is usual a disk (hard/floppy/optical etc) 7. M aking Decisions connected to the computer bus by means of 8. Looping some interface 9. A rrays 10. B asics of pointers • Accessing data in files is much slower than 11. S trings from memory, but files are more permanent 12. B asics of functions and can be larger 13. M ore about functions 14. Files 14. D ata S tructures 16. C ase study: lottery num ber generator Streams in C Streams in C • To use a file we must first open a stream, when we • In C each file is associated with a buffer are finished the stream must be closed to form a stream • When <stdio.h> is included in a program, • A buffer is simply an area of memory 3 streams are automatically opened that is used for temporary storage – stdin, stdout, stderr • They are special in that they are normally • This is because it is more efficient to connected to the keyboard and screen rather than move data to/from files in “chunks” a disk file however as weve already seen they can be redirected buffer file • When the program has finished running these stream streams are automatically closed File Structure Directories, paths and filenames • Most operating systems organise secondary • There are 2 sorts of file storage in a tree structure using directories. – text files which use ASCII codes to store text data • A directory is a file containing the names of other – binary files which are used to store raw binary data files and where they are stored • In this course we will only deal with text files • Each file is identified by a filename file name myfile.c beginning of file /* This is a file*/[\n] • Its location is given by a path #include <stdio.h>[\n] • e.g. /usr/students/1996/A.Person/C/myfile.c [\n] lines of text main()[\n] root of directory tree director filename {[\n] • If “C” is the current directory we can refer to the file }[\n] simply as “myfile.c” or we can give the full path end-of-file marker [EOF] 1

Recommend


More recommend