how putchar function is used within a c program


How putchar function is used within a C Program ?

The following program reads each character in the first line of input entered at the terminal's keyboard. It uses putchar to display, on the terminal's screen, each character from the line.

#include

int c;

main()

{

puts("Enter a line of input.");

while ( (c = getchar()) != '\n' ) /* Look for newline */

{

putchar(c);

}

putchar('\n');

}

putchar writes one character to the standard output file, stdout. But getchar

Reads and returns the next character from the standard input file, stdin.

Syntax

#include

int getchar(void);

The getchar macro reads the next character from the preopened file pointed to by stdin. The file pointed to by stdin is usually associated with the terminal's keyboard. If the file is at end- of-file, getchar sets the end-of-file indicator for stdin. If a read error occurs, the macro sets the error indicator associated with stdin. If the file is at end-of-file or a read error occurs, getcharsets the external variables errno and os_errno to the appropriate error code number.

The getchar macro returns an integer value representing the next character from stdin. If a read error occurs or the file is at end-of-file, getchar returns EOF.

 

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: how putchar function is used within a c program
Reference No:- TGS0305460

Expected delivery within 24 Hours