c语言程序设计国外,国外C语言程序设计英文课件-lecture13.ppt

国外C语言程序设计英文课件-lecture13

Lecture 13 Outline Standard Input and Output Standard Input and Output (I/O)– Review & more Buffered/unbuffered input Character I/O Formatted I/O Redirecting I/O to files. Pipes Bibliography: [Kochan, chap 16.1, 16.2] [Kernighan&Ritche, chap 7.1, 7.2] [C Primer, chap 8] Standard Input and Output input and output devices: such as keyboards, disk drives, printers, screen. The C language itself does not have any special statements for performing input/output (I/O) operations; all I/O operations in C must be carried out through function calls. These functions are contained in the standard C library: #include Advantages: Portability: they work in a wide variety of computer environments General character: they generalize to using files for I/O Disadvantage: Less performance: they don't take advantage of features peculiar to a particular system. Kinds of Standard I/O functions Character I/O getchar, putchar Formatted I/O scanf, printf Character I/O example /* echo.c -- repeats input */ #include int main(void) { char ch; while ((ch = getchar() ) != ‘*’) putchar(ch); return 0; } I/O streams C treats input and output devices the same as it treats regular files on storage devices. In particular, the keyboard and the display devices are treated as files opened automatically by every C program. Conceptually, the C program deals with a stream instead of directly with a file. A stream is an idealized flow of data to which the actual input or output is mapped. Keyboard input is represented by a stream called stdin, and output to the screen is represented by a stream called stdout. The getchar(), putchar(), printf(), and scanf() functions are all members of the standard I/O package, and they deal with these two streams. EOF One implication of I/O streams is that you can use the same techniques with keyboard input as you do with files. For example, a program reading a file needs a way to detect the end of the file so that it knows

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值