{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cpts121-4-1 - Always close a file when you’re done...

Info icon This 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  Hundhaus 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
Image of page 1

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

View Full Document Right Arrow Icon
2 C ptS  121 L3-2 – 9/14/09 Pro f. C hris  Hundhaus 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); Always close a file when you’re done:
Image of page 2
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 you’re done: fclose(infile); fclose(outfile); 3 C ptS 121 L3-2 – 9/14/09 Pro f. C hris Hundha us e n Let’s 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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern