Skip to Content
C语言核心技术(原书第2版)
book

C语言核心技术(原书第2版)

by Peter Prinz, Tony Crawford
August 2017
Intermediate to advanced
798 pages
17h 44m
Chinese
China Machine Press
Content preview from C语言核心技术(原书第2版)
205
第13章
输入和输出
程序必须能够将数据写入文件或者物理输出设备,例如显示器或打印机,并且能够从
文件或输入设备,例如键盘读取数据。
C
语言标准库提供了许多函数以让我们达到该目
的。本章将综述标准库中的输入输出部分,这部分通常被称为
I/O
链接库。关于个别函数
的更多细节,请参见第
18
章的详细说明。除了这些链接库函数以外,
C
语言本身并没有
提供对输入或输出的支持。
所有输入输出基本函数、宏以及为其定义的类型,全部都在头文件
stdio.h
中进行声明。
为
wchar_t
类型的宽字符对应声明的输入输出函数,包含在头文件
wchar.h
中。
作为传统标准
I/O
函数基础上的一种补充,
C11
标准新增了许多新函数以支撑更加安
全的编程,尤其是在复制数据时检查数组边界。这类函数名称都以后缀
_s
结尾(例
如
scanf_s()
)。
可由用户选择是否支持这类函数。当在给定的
C
语言实现版本中定义宏
__STDC_LIB_
EXT1__
,就启用了这类函数(请参见
16.2
节)。
13.1 流
从
C
程序角度来看,无论程序一次读写的是一个字符、字节、文本行还是给定大小的数
据区域,作为输入输出的各种文件和设备统一以逻辑数据流的方式展现。
C
中的数据
流可以是文本流或者二进制流,甚至在某些系统上,就连这样的差异也不存在。通过
使用函数
fopen()
(或
tmpfile()
)打开一个文件就会建立一个新的流,直到调用函数
fclose()
,
该流才会结束。
C
语言将文件的管理工作交由运行环境(也就是运行程序的
系统)。因此,流是一个传输通道,利用该通道,数据可以从运行环境流入程序中, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)

Publisher Resources

ISBN: 9787111562207