458 Programming and Data Structures
QUTJPUI i
Enter a file name: TEXT
PROGRAMMING IN C
Explanation In the above program the file is opened in read only mode. The read () declaration
within the w h ile loop reads single character from the file destined by the file handler s. Theputch
() statement following the read () declaration shows the read character on the console. The
w h ile loop ends when the end of file is detected.
d. Setting Buffer The size of buffer can be set using setbu f () function. This function is defined
in " s t d i o . h/f. The syntax of setbu f () is as follows.
Syntax void se tb u f( FILE *fp , char * b u f f e r ) ;
13.37 Write a program to set a buffer size using setbufO function.
# include <stdio.h>
# include <conio.h>
void main()
{
char bu ff [22] ;
c l r s c r ( ) ;
setbuf(stdout,buff);
printf (" tThis book teaches C ");
fflush(stdout);
Q12XELDT;
This book teaches C
Explanation In the above program a character array buff [22] is declared. The setbuf () function
sets the buffer size as per the size of bu ff [22] array. Theprintf () statement displays the message
written in it. If the characters written in the prin t f () statement are more than buffer size i.e. 22 the
program will be terminated with critical error. Hence, the text that is to be displayed using any output
function should be less or equal the size of buffer.
13.9 COMMAND LINE ARGUMENTS
An executable program that performs a specific task for operating system is called as command.
The commands are issued from the prompt of operating system. Some arguments are to be associated
with the commands hence these arguments are called as command line arguments. These associated
arguments are passed to the program.
In C language every program starts with amain () function and that it marks the beginning of the
program. We have not provided any arguments so far in the main ( ) function. Here, we can make