• No results found

IOinC-9,10,-9-11.ppt

N/A
N/A
Protected

Academic year: 2020

Share "IOinC-9,10,-9-11.ppt"

Copied!
13
0
0

Loading.... (view fulltext now)

Full text

(1)

I/O in C

I/O in C

(2)

Input/Output in C

Input/Output in C

C has no built-in statements for

input or output.

A library of functions is supplied

to perform these operations. The

I/O library functions are listed the

“header” file <stdio.h>.

You do not need to memorize

(3)

Streams

Streams

 All input and output is performed with

streams.

 A "stream" is a sequence of characters

organized into lines.

 Each line consists of zero or more characters

and ends with the "newline" character.

 ANSI C standards specify that the system must

(4)

Types of Streams in C

Types of Streams in C

 Standard input stream is called

"stdin" and is normally connected to the keyboard

 Standard output stream is called

"stdout" and is normally connected to the display screen.

 Standard error stream is called

(5)

Formatted Output with

Formatted Output with

printf

printf

printf ( ) ;

 This function provides for formatted

output to the screen. The syntax is: printf ( “format”, var1, var2, … ) ;

 The “format” includes a listing of

the data types of the variables to be output and, optionally, some text and control character(s).

 Example:

float a ; int b ;

scanf ( “%f%d”, &a, &b ) ;

(6)

Formatted Output with

Formatted Output with

printf

printf

 Format Conversion Specifiers:

d -- displays a decimal (base 10) integer

l -- used with other specifiers to indicate a "long"

e -- displays a floating point value in exponential

notation

f -- displays a floating point value

g -- displays a number in either "e" or "f" format

c -- displays a single character

(7)

Input/Output in C

Input/Output in C

scanf ( ) ;

 This function provides for formatted input from the keyboard. The syntax is:

scanf ( “format” , &var1, &var2, …) ;

The “format” is a listing of the data types of the variables to be input and the & in front of each variable name tells the

system WHERE to store the value that is input. It provides the address for the

variable.  Example:

float a; int b;

(8)

Input/Output in C

Input/Output in C

getch ( ) ;

 This function provides for getting

character from the keyboard it not display the character and return immediately.

 Example:

char ch;

(9)

Input/Output in C

Input/Output in C

getchar ( ) ;

 This function provides for getting

exactly one character from the keyboard it will return the next character after

that it will wait for enter then it will return.

 Example:

char ch;

(10)

Input/Output in C

Input/Output in C

getche ( ) ;

 This function provides for getting

character from the keyboard and echo this character on screen and return immediately.

 Example:

char ch;

(11)

Input/Output in C

Input/Output in C

putchar (char) ;

 This function provides for printing

exactly one character to the screen.

 Example:

char ch;

ch = getchar ( ) ; /* input a character from kbd*/

(12)

Input/Output in C

Input/Output in C

getc ( *file ) ;

 This function is similar to getchar( )

except the input can be from the keyboard or a file.

 Example:

char ch;

ch = getc (stdin) ; /* input from keyboard */

(13)

Input/Output in C

Input/Output in C

putc ( char, *file ) ;

 This function is similar to putchar ( )

except the output can be to the screen or a file.

 Example:

char ch;

ch = getc (stdin) ; /* input from keyboard */

putc (ch, stdout) ; /* output to the screen */

putc (ch, outfileptr) ; /*output to a file */

Winter Quarter

Lect 6

References

Related documents

development of the two major components that dominated Puerto Rican economic and social structures until the third-quarter of the nineteenth century: sugar production and slave

Polarity detection is explored and two experiments were done to identify the best com- bination of preprocessing, features and machine learning techniques to create an optimal model

Penelitian ini menunjukkan bahwa : 1) latar belakang dan motif rumah tangga buruh migran di Sugihwaras mengakses tanah timbul antara lain ; harganya yang murah,

Captains or qualified members running for Assistant Chief shall have two (2) years time in grade as a Captain with current and up to date North Carolina Firefighter Level

Two key parameters in WSI are the optical path difference resolution, dL , which varies inversely with the total wavenumber scan range D k, and the unambiguous depth range, D z,

In our city, all children who make allegations of sexual abuse are brought to the Philadelphia Safety Collaborative – a partnership between the Philadelphia Children’s

daily press review, daily news summary, daily news digest, media alerts, thematic media review, weekly previews and daily social media summaries deliverable on working days

› Altiscale offers white-glove service for Hadoop at a self-service price. Altiscale, founded in 2012, delivers a Hadoop- and Spark-based platform in the cloud that also