Standard streams (ITI8510): erinevus redaktsioonide vahel
Mine navigeerimisribale
Mine otsikasti
Uus lehekülg: '{{iti8510}} ''This exercise is about standard streams. While we will return to the specific inputs, it is vital to understand how the streams work for most of the exercises.'' =...' |
Resümee puudub |
||
| 10. rida: | 10. rida: | ||
:* Copy a file | :* Copy a file | ||
:* Create and edit a text file | :* Create and edit a text file | ||
# Fix your first program so that it shows error messages to stderr using either [http://linux.die.net/man/3/fprintf fprintf() or | # Fix your first program so that it shows error messages to stderr using either [http://linux.die.net/man/3/fprintf fprintf()] or [http://linux.die.net/man/3/perror perror()] | ||
== Hints == | == Hints == | ||
Redaktsioon: 11. september 2013, kell 19:17
| Real-Time Operating Systems and Systems Programming |
| [ @ ] |
This exercise is about standard streams. While we will return to the specific inputs, it is vital to understand how the streams work for most of the exercises.
Task
- Write a program named show_input which reads file 'input.txt' ( fopen(), fread(), fclose() ) and displays it to the standard output (use fwrite() or fprintf instead of printf() and use stdout stream for output).
- Write a program named my_cat which reads from stdin and then outputs each line to stdout using only fgetc() and fputc() functions.
- Find a way to use the program to:
- Show a text file
- Copy a file
- Create and edit a text file
Hints
- These tasks are simple enough to figure out without getting off-the-shelf answer from google. Your brain will thank you. If you still want to copy example code -- do it by hand at least. It's pointless waste of your own time to copy-paste and fix code you found online.
- You have variables named stdin, stdout and stderr which correspond to streams which the system opens for you upon program launch. They arrive with inclusion of stdio.h.
- Standard streams can be redirected on the command-line using < > 2> and | signs. You should know find out what they do.