W09-BasicFileRead

W09-BasicFileRead - Basic File Input 10/10/05 1 File...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
10/10/05 1 Basic File Input 10/10/05 2 File Properties • Files have names. • Files have size (in bytes). • Files hold different kinds of data. • Text file: Text characters and white space. • Binary file: Any 8-bit byte OK. • Files are like memory stored on a disk. 10/10/05 3 File Reading fopen( filename, mode ) int a, b, c; FILE *fp; /* *fp means fp points to a FILE structure */ fp = fopen("data.txt", "r"); fscanf( filepointer, string , &var1, &var2, …) /* read three integers from the file */ f scanf(fp, "%d %d %d", &a, &b, &c); fclose( filepointer) fclose(fp); /* close the file */
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10/10/05 4 Data Flow to/from HD Console App Debug.exe OS (WinXP OS-X Linix, etc) FILE data structure size, location, current position buffers, etc. Hard Disk (tracks, clusters) fopen fscanf cmds data 10/10/05 5 File Mode - text files mode can be "r" "w", "a" • "r" open a text file for reading from the beginning (fscanf) • "w" open a text file for writing from the beginning (fprintf). Replaces any existing
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/28/2009 for the course CS 151 taught by Professor Staff during the Spring '08 term at Oregon State.

Page1 / 4

W09-BasicFileRead - Basic File Input 10/10/05 1 File...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online