Chapter - 14: More Issues In Input-Output

How will you use the following program to:


A
Sections
1
Exercises

A

B

1

2

3

- Copy the contents of one file into another.
- Print a file on the printer.
- Create a new file and add some text to it
- Display the contents of an existing file.

#include "stdio.h"
main( )
{
 char ch, str[10] ;
 while ( ( ch = getc ( stdin ) ) != -1 )
 putc ( ch, stdout ) ;
}

Ans:

(a) Let the file name is "prog.c" so its executable file will be “prog.exe”. Now, type this command in the command prompt

(1) - To copy the content of one file into another.
prog.exe > File1.txt < File2.txt
Input from file1 and put the output in file 2

(2) – To create a new file and add some text to it.
prog.exe < NewFile.txt
Input from keyboard and output in the file specified.

(3) – To display contents of an existing file.
prog.exe > File1.txt
Input from the file1 and output in the screen


© 2020 Garbage Valuegarbage value logo