Charactor Input and Output (k&R)

本文介绍了C语言标准库中处理字符数据的基本方法。讲解了文本流的概念,并详细说明了getchar和putchar函数如何用于逐个字符地读写。此外,还提到了文件输入将在后续章节讨论。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值