99

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 99| File Manipulations File - From the Perspective of the Computer File - Just another Kind of Stream The First Look Opening Files | fopen() Reading From Files | fscanf() Writing to Files | fprintf() Closing Files | fclose() Inquiring End-Of-File | feof() Example | Data File Processing Readings Exercises CSC 1500 { Lecture 99 1 Overview General input/output for les. Files must be opened before use. Files must be closed after use. Basic le operations: reading, writing, and appending. CSC 1500 { Lecture 99 2 File - From the Perspective of the Computer Hard Disk Autoexec.bat Config.sys bcc32.exe hello.c hello.obj hello.exe assignment1.c stdio.h ctype.h math.h ... #include <stdio.h> #define PI 3.1 int main(void) { int i; /* ... */ return 0; } #include <stdio.h>\n#define PI 3.1\nint main(void)\n{\n... CSC 1500 { Lecture 99 3 File - Just another Kind of Stream Keyboard input is considered as an input stream. Monitor screen output is considered as an output stream. Similarly, a File is considered as another input stream when we read its content from the disk. Likewise, a File is considered as another output stream when we write its content to the disk. keyboard monitor read le write le ! ! input stream output stream input stream output stream ! scanf()/getchar()/... printf()/putchar()/... ! fscanf()/... fprintf()/... CSC 1500 { Lecture 99 4 The First Look #include <stdio.h> int main(void) { FILE* int fptr ICQnumber /* open a file */ /* process the file */ /* read its content */ fptr=fopen("contact.txt...
View Full Document

This note was uploaded on 05/23/2010 for the course COMPUTER S CSC1500 taught by Professor Fung during the Spring '10 term at CUHK.

Ask a homework question - tutors are online