How putchar function is used within a c program, Computer Engineering

Assignment Help:

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.

 


Related Discussions:- How putchar function is used within a c program

What is thread, What is Thread? A thread, sometimes termed a lightweigh...

What is Thread? A thread, sometimes termed a lightweight process (LWP), is a fundamental unit of CPU utilization; this comprises a thread ID, a register set, a program counter

Trace the pseudo-code, Consider the following pseudo-code segment. 1.  i...

Consider the following pseudo-code segment. 1.  input y {y is a three-digit hexadecimal number} 2.  d ← 0 3. for i = 1 to 3      3.1. char ← i th character from y readin

What is ''preemption'' program, Program 'preemption' is? Ans. Forced de...

Program 'preemption' is? Ans. Forced de allocation of the CPU from a program that is executing on the CPU is called preemption program.

Where arq is transmitted, ARQ is transmitted in the event of: (A)  Los...

ARQ is transmitted in the event of: (A)  Loss of signal                          (B) Error in received data (C)  Improve reliability                  (D) During time out

External communication interfaces, External interface is interface between ...

External interface is interface between I/O interface and peripheral devices. Interface can be characterised into 2 main categories: (a) parallel interface and (b) serial interface

Cg, raster scan display system

raster scan display system

Explain the access methods used in lans, Explain the access methods used in...

Explain the access methods used in LANs. Access methods utilized in LAN: i. Switched access: this is used in LANs which are assigned around CBXs. Electronic switching

What are the features of the hardwired control, What are the features of th...

What are the features of the hardwired control? A controller that uses this approach can function at high speed. It has little flexibility and the complexity of the instruction

Determine the binary equivalent of hexadecimal FA, The binary equivalent of...

The binary equivalent of (FA) 16   is ? Ans. (FA) 16 = (11111010) 10

Connectivity options accessible to internet subscribers, What are the diffe...

What are the different connectivity options accessible to Internet Subscribers? Explain in detail. Internet Connectivity Options: Internet access is perhaps one of the ma

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd