C File Processing - I Math 130 B Smith: Eval: 3. Energy and excitement helped for avg graphics. Gen interest. A bit wordy, henced redundant in some parts since most is discussed. Good for handout, bad for lectures. B Smith: 4/13/2005 9:54 AM: Rate: 3, low discussion, implement, “Your turn…” Time: 50 minutes B Smith: Rate:2/4 More examples needed, fewer words. B Smith: Sp06: rate 2.5 Worked mostly from examples 11.1 and 11.2. Need better examples.
18
Embed
C File Processing - I Math 130 B Smith: Eval: 3. Energy and excitement helped for avg graphics. Gen interest. A bit wordy, henced redundant in some parts.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
C File Processing - I
Math 130
B Smith:
Eval: 3. Energy and excitement helped for avg graphics. Gen interest. A bit wordy, henced redundant in some parts since most is discussed. Good for handout, bad for lectures.
B Smith:
Eval: 3. Energy and excitement helped for avg graphics. Gen interest. A bit wordy, henced redundant in some parts since most is discussed. Good for handout, bad for lectures.
if (inFile == NULL) { printf("\nThe file cannot be opened."); printf("\nPlease check that the file currently exists."); exit(1); /* all open streams are closed */ }
printf("\nThe file has been successfully opened for reading"); return 0;}
Opening a File for Writing:
• This creates a new file makes the file available for output from the function
opening the file if a file with the same name exists, the old file is
erased
outFile = fopen(“prices.bnd”,”w”);
pgm 11.2 – Writing a File example
#include <stdlib.h>#include <stdio.h>int main(){ int i; FILE *outFile; /* FILE declaration */ float price[] = {39.95,3.22,1.03}; /* a list of prices */ char *descrip[] = { "Batteries", /* a list of */
"Bulbs", /* descriptions */ "Fuses"};
outFile = fopen("prices.txt","w"); /* open the file */ if (outFile == NULL) { printf("\nFailed to open the file.\n"); exit(1); } for(i = 0; i < 3; ++i) fprintf(outFile,"%-9s %5.2f\n",descrip[i],price[i]);