cpts121-4-1 - Always close a file when youre done:...

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

View Full Document Right Arrow Icon
1 C ptS  121 L3-2 – 9/14/09 Pro f. C hris  Hundha us e n CptS 121 Spring ‘09 Lecture 4-1 HK Chapter 3: Basic File Processing with Functions (cont.) Lecture Outline I. Input and Output File Processing II. Penn Relays Example
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 C ptS  121 L3-2 – 9/14/09 Pro f. C hris  Hundha us e n File Processing Quick Reference To work with files: #include <stdio.h> To open a file for reading: FILE* infile = fopen(“myinfile.txt”,”r”); To open a file for writing: FILE* outfile = fopen(“myoutfile.txt”,”w”); To read from a file: fscanf(infile,”%d”, &myint); To write to a file: fprintf(outfile,”Writing an integer: %d”,myint);
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Always close a file when youre done: fclose(infile); fclose(outfile); 3 C ptS 121 L3-2 9/14/09 Pro f. C hris Hundha us e n Lets Do Programming Project 6 to Practice File Input and Output Four track stars have entered the mile race at the Penn Relays. Write a program that reads in the race time in minutes and seconds for four runners and computes the speed in feet per second and meters per second, and outputs to a file each runners stats (race time, feet per second, and meters per second), one runner per line. Hints: There are 5,280 feet in one mile, and one kilometer equals 3,282 feet...
View Full Document

This note was uploaded on 01/25/2011 for the course CPTS 121 taught by Professor Hundhaus during the Spring '09 term at Washington State University .

Page1 / 3

cpts121-4-1 - Always close a file when youre done:...

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