File I/O ● ●

stdin stdout

FILE* file;

file = fopen(“file.txt”, “r”); ● ● ○ “r”

“w”

“a”

● fgetc ● fgets ● fread ● fseek

● ● ● ●

fputc fputs fprintf fwrite

fclose(file);

● ●

Example #1 Writing to a file #include #define STUDENTS 3 int main(void) { int scores[] = { 96, 90, 83 }; FILE* file = fopen(“database”, “w”); if (file != NULL) { for (int i = 0; i < STUDENTS; i++) { fprintf(file, “%i\n”, scores[i]); } fclose(file); } }

#include int main(int argc, char* argv[]) { if (argc < 2) { printf("Usage: cat file [file ...]\n"); return 1; }

Example #2 What does this program do?

for (int i = 1; i < argc; i++) { FILE* file = fopen(argv[i], "r"); if (file == NULL) { printf("cat: %s: No such file or directory\n", argv[i]); return 1; } for (int c = fgetc(file); c != EOF; c = fgetc(file)) { putchar(c); } fclose(file); } return 0; }

File I/O

File I/O. We are used to reading from and writing to the terminal: ○ read from stdin. ○ write to stdout. But we can also read from and write to files!

482KB Sizes 3 Downloads 200 Views

Recommend Documents

IO (41am)
May 1, 2002 - grated Optic Systems”, Journal Of Lightwave Technology, vol. 7, pp. 3-10, Jan. ...... degree of spectral coherence by use of a wave-front-folded interferometer. .... tomography and high frequency intravascular ultrasound.” Heart ...

IO (41am)
May 1, 2002 - Mueller-Matrix Optical Coherence Tomography and Application in. Burn Imaging ..... Chance, B., J. S. Leigh, et al. (1988). “Comparison ofTime- ...

M IO/ INTA
2.a) Write a subroutine for 8085 to obtain 1 milli sec. delay. The crystal frequency ... 6.144 MHz. Use this subroutine write a programme for 50 milli seconds delay.

IO Schedule.pdf
4:55pm 16U South Florida 2 4:55pm 16U North Texas 3 ... All Infield/Outfield sessions are scheduled for the National Training Complex in ... IO Schedule.pdf.

IO Subsystems.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. IO Subsystems.

iO Senior PHP.pdf
... loading more pages. Retrying... iO Senior PHP.pdf. iO Senior PHP.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying iO Senior PHP.pdf.

iO Junior Dev.pdf
Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. iO Junior Dev.pdf. iO Junior Dev.pdf. Open. Extract. Open with.

iO Senior JavaScript.pdf
Loading… Page 1. Whoops! There was a problem loading more pages. Retrying... iO Senior JavaScript.pdf. iO Senior JavaScript.pdf. Open. Extract. Open with.

iO Middle PHP.pdf
There was a problem loading more pages. Retrying... iO Middle PHP.pdf. iO Middle PHP.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying iO Middle ...

Krebs IO 2015.pdf
that it did not coalesce until well into the 1950s, and that it began to erode even. before the Vietnam War's Americanization in 1965. To make sense of this puzzle ...

Manuale Mini IO device.pdf
Loading… Page 1. Whoops! There was a problem loading more pages. Manuale Mini IO device.pdf. Manuale Mini IO device.pdf. Open. Extract. Open with.

290110_PCF8574 SOIC16 (I2C-IO).pdf
2C to Parallel-Port Expander. • Open-Drain Interrupt Output. • Compatible With Most Microcontrollers. • Latched Outputs With High-Current Drive. Capability for Directly Driving LEDs. • Latch-Up Performance Exceeds 100 mA. Per JESD 78, Class I

277857439-IO-DEB-TACE-IO-Journal-Club-Primer-Final-pdf ...
Purpose. Page 4 of 9. 277857439-IO-DEB-TACE-IO-Journal-Club-Primer-Final-pdf.pdf. 277857439-IO-DEB-TACE-IO-Journal-Club-Primer-Final-pdf.pdf. Open.

iO Pre-sales manager.pdf
Sign in. Loading… Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying.

1510294110929-rec-io-advert.pdf
Chief Customer Service Officer- on contract basis” and addressed to The General. Manager (HRM), Human Resources Management Department, Dena ...

Krebs IO Appendix Final.pdf
Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Krebs IO Appendix Final.pdf. Krebs IO Ap

Chapter 09-IO Devices.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Chapter 09-IO ...

Comunicato Io amo Helen.pdf
Le luci sono di Lucio Diana. Info www.nuovoteatroabeliano.com tel 080.5427678. Page 1 of 1. Comunicato Io amo Helen.pdf. Comunicato Io amo Helen.pdf.

Mitsubishi pajero io service manual pdf
Displaying Mitsubishi pajero io service manual pdf. Mitsubishi pajero io service manual pdf. Mitsubishi pajero io service manual pdf. Open. Extract. Open with.

DN566 - Quad IO-Link Master with Higher Current ... - Linear Technology
In addition to the data pin (C/Q), the IO-Link Type A ... When the active driver changes state, it will generate ... swap channels as higher current SIO drivers.

Download File
ii Create a .GIF image with textual animation for the following theme: Flower and its parts. 30. 3 i Draw a smiley face and reposition the face along a circular path.

pdf-file
Nov 7, 2012 - consists in asking subjects individually and then as a group to tell ..... We have lost the data of two groups due to a problem with a computer during the ..... Philosophical Transactions of the Royal Society B: Biological Sciences,.

252849284-IO-Procedural-Committee-Survival-Guide-pdf.pdf ...
252849284-IO-Procedural-Committee-Survival-Guide-pdf.pdf. 252849284-IO-Procedural-Committee-Survival-Guide-pdf.pdf. Open. Extract. Open with. Sign In.