`
t225com
  • 浏览: 660141 次
文章分类
社区版块
存档分类
最新评论

Charactor Input and Output (k&R)

 
阅读更多

这是K&R所写的<THE C PROGRAMMING LANGUAGE>中的一段讲字符串的,字符串原始设定是与INT有关,读一读原版的还是能体会不少作者的心思的。

We are now going to consider a family of related programs for processing character data . You will find that many programs are just expanded versions of the prototypes that we discuss here.

The model of input and output supported by the standard library is very simple . Text input or output , regardless of where it originates or where it goes to,is dealt with as streams of charccters. A text stream is a sequence of characters divided into lines ; each line consists of zero or more characters followed by a newline character. It isthe responsibility of the library to make each input or output stream conform to this model ; the C programmer using the library need not worry about how lines are represented outside the program.

The standard library provides several functions for reading or writing one character at a time, of which getchar and putchar are the simplest.Each time it is called ,getchar reads the next input character from a text stream and returns that as its value.That is after

Code:
  1. C=getchar()

the variable c contains the next character of input.The characters normally conme form the keyboard;input from files is discussed in Chapter 7.

The function putchar prints a character each time it is called:

Code:
  1. putchar(c)

prints the contents of the integer variable c as a character,usually on he screen.Calls to putchar and printf may be interleaved; the output willappear in the order in which the calls are made.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics