Chp 13 More Issues In Input/Output Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

File copy programs where we transfered data char by char at the beginning, is typed first then compiled then executed.
2 ways it can be improved:

A
  1. to use file-copy utility there is no need to compile it every time. It means program must be executable at command prompt ( A> or C> : MS-DOS, Run dialog: Windows, $ prompt : Unix)
    [F9, F7 to compile program, in Unix we get exe file always.]
  2. Instead of program prompting us, we should be able to enter source and traget filenames at command prompt.
    filecopy PR1.C PR2.C
    using argc and argv, passing source n target filename to main().
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Using argc and argv

A

main( int argc, char *argv[ ] ) {…}
The arguments that we pass on to main() at the command prompt are called command line arguments.
main() can have 2 arguments, traditionally named as argc and argv.
argv is array of pointers to string and argc is no. of strings to which argv points.
its a good habit to check if correct number of arg are passed on to main().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

feof()

A

it returns zero if end of file is not reached.
Its a Macro.
returns non zero if end of file is reached.

while( !feof(fs) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Detecting Errors in reading/Writing :

A

if (ferror() )
{ perror ( “Trial” ); break; }

both func are std lib functions. ferror returns 0 in case of no errors and non zero otherwise.
perror prints error message specified by compiler and “ Trial “ precedes that msg. Example:
Trial: Permission denied.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Standard I/O device:

A

Most OS’s predefine pointers for 3 standard file:

stdin: Standard Input Device(Keyboard).
stdout: Std output device (VDU).
stderr: Standard Error device (VDU).

MS DOS: stdprn(printer), stdaux (auxiliary device, serial port).
No need to open or close these.
example:
fputc( ch, stdprn);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

I/O Redirection:

A

OS makes assumptions like input comes from keyboard and output goes to VDU.
Redirection permits us to change these assumptions.
This approach is more convenient and flexible than providing a separate function in program.

To use redirection facility is to execute the program from the command prompt, inserting the redirection symbols at appropriate places.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

End of file character:

A

Ctrl+Z

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Redirecting the output:

A

using stdout causes output to print on screen, but the redirection operator ‘>’ causes it to be written to the file whose name follows. Example:
C>UTIL.EXE>POEM.TXT
(UTIL gets input from stdin and sends output to stdout.)

DOS has PRN for printer, so
C>UTIL.EXE>PRN
this will redirect it to printer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Redirecting the Input:

A

Using Input redirection operator

C>UTIL.EXE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Wht kind of a program is filter:

A

the input of program comes from a file via redirection and at the same time its output can be redirected to a file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Redirection of Input and Output Together:

A

C>UTIL.EXEPOETRY.TXT
input from newpoem and output to poetry.

C>UNTILPRN
newpoem to printer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What if we try to recieve input from a file to whom we send output to?

A

the output file gets erased before its written to, so by the time we manage to receive the input from a file it is already erased.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

piping

A

To feed one’s output directly as input to another file. It’s done using ‘|’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly