没有料酒用什么去腥| 琉璃是什么材质| 宁五行属性是什么| 什么叫逻辑思维| 外科医生是做什么的| 自愈是什么意思| 胃部彩超能检查出什么| 地球属于什么星系| 哭得什么| 男人肾虚吃什么补得快| 卧底大结局是什么| 什么给我带来快乐| 男生学什么技术吃香| 躺枪是什么意思| 厚黑学是什么意思| 伊犁在新疆什么位置| 脸上爱出油是什么原因| 为什么减肥不建议喝粥| 无名指是什么经络| 皮肤软组织感染是什么意思| 72年属什么的生肖| 吃什么东西涨奶最快| 花子是什么意思| 荷尔蒙是什么| 打三个喷嚏代表什么| 性冷淡是什么| 甲状腺结节什么引起的| 乳腺挂什么科室| 腹腔淋巴结是什么意思| 全麻手术后为什么不能睡觉| 最近老做噩梦是什么原因| 轭是什么意思| 异丙嗪又叫什么名| 不宁腿综合症吃什么药| 一什么鹿角| 吃黄瓜有什么好处和坏处| 迷走神经是什么| coa什么意思| gv是什么意思| 中国的国球是什么球| 1994年属狗的是什么命| 梦见很多人是什么意思| 出殡是什么意思| 昕五行属什么| 白斑是什么原因引起的| pg在医学是什么意思| 梦见老公出轨预示什么| 玉五行属性是什么| 眼睛红是什么病| 多吃核桃有什么好处和坏处| 胆结石是什么原因导致的| 儿童乘坐高铁需要什么证件| 言字旁的字和什么有关| 心境什么意思| 脐血流检查是什么| 三月底是什么星座| 何炅和谢娜是什么关系| 孕酮低什么原因造成的| 尿液浑浊是什么原因| 吃什么增强性功能| 尿酸高注意什么| 喝茶有什么好处| 整夜失眠是什么病| 下肢静脉血栓挂什么科| 来月经喝什么茶好| gp是什么意思| 缺钾是什么症状| 小肚子发胀是什么原因女性| 手上为什么长湿疹| 浮尘是什么意思| 面粉和淀粉有什么区别| 烤鱼用什么鱼| 烤鸭为什么那么便宜| 什么是格局| 沾沾喜气什么意思| 拔了尿管尿不出来有什么好办法| 梦见打雷是什么意思| 子宫切除有什么影响| 哈哈哈是什么意思| 不完全性右束支阻滞是什么意思| 吃什么水果可以通便| 甲流是什么病| 豸是什么意思| 肚子突然疼是什么原因| 家里为什么会有蜘蛛| 五花八门是指什么生肖| 心眼小是什么意思| 心脏支架是什么材料做的| 什么神什么注| 感冒咳嗽吃什么药好| 头晕想吐是什么原因| 什么是非萎缩性胃炎| 什么动物怕水| bpd是什么意思| 火龙果和什么相克| 愚人是什么意思| 绿豆跟什么一起煮最好| 兰花的花语是什么| 什么动物睡觉不闭眼睛| 什么是地中海饮食| 樟脑丸是干什么的| 一什么狼| 眼睛肿是什么问题| 血钾查什么项目| l表示什么单位| 吃完羊肉不能吃什么水果| 八面玲珑代表什么生肖| 实则是什么意思| 嗨体水光针有什么功效| 扁桃体肿大吃什么药好| 你是什么星座| 梦见父亲去世预示什么| 穆字五行属什么| 飞的第一笔是什么| bosch是什么牌子| 九月二十三是什么星座| 脚底拔罐对女人有什么好处| 红色爱心是什么牌子| 1958年属什么| 一什么山泉| 什么品种荔枝最好吃| 小孩智力发育迟缓挂什么科| 发粉是什么| 心绞痛吃什么药最好| 权字五行属什么| 三七粉什么时间吃最好| 鸡枞菌长在什么地方| 肤如凝脂是什么意思| 熬夜吃什么保健品| 11月16日是什么星座| snidel是什么牌子| 泉字五行属什么| 40周年是什么婚| 琼字代表什么生肖| 考警校需要什么条件| 支原体感染咳嗽吃什么药| 精神心理科主要治疗什么疾病| 经常口腔溃疡吃什么维生素| 吃什么可以回奶| 撅眼是什么原因造成的| 桂圆有什么功效| 割包皮有什么影响| 闻鸡起舞是什么意思| 680分能上什么大学| 死了妻子的男人叫什么| 七月二十号是什么星座| 内膜b型是什么意思啊| 什么叫热射病| 成五行属性是什么| 分泌物豆腐渣状是什么原因| 口周皮炎用什么药膏| 什么是白血病| 自来熟是什么意思| 租赁费计入什么科目| 拔了牙吃什么消炎药| 现在是什么意思| 打新股需要什么条件| 吉利丁片是什么做的| 做梦梦到对象出轨是什么意思| 2004年是什么生肖| 78年属什么| 产后恶露吃什么排干净| 七月份生日是什么星座| 拔完牙吃什么药| 硫磺有什么作用| 压疮用什么药最快能好| 女生下面叫什么| 突然眼睛充血是什么原因引起的| 江诗丹顿是什么档次| 左耳朵嗡嗡响是什么原因引起的| 看望病人买什么水果| 轻度异常脑电图是什么意思| 抽筋是缺什么| 安全期什么时候| 吃什么药不能喝酒| 口腔溃疡是什么原因造成的| 羊悬筋是什么样子图片| 空调数显是什么意思| 吸尘器什么牌子好| 糖尿病2型是什么意思| 大便粘稠吃什么药| 内热吃什么药清热解毒| 肉苁蓉与什么搭配好| 水肿是什么原因引起的| 胆固醇高有什么症状| 印模是什么意思| 菠菜为什么要焯水| 孟姜女姓什么| 长期口臭挂什么科| 什么药通便最快| 腿抽筋挂什么科室| 胃阴虚有什么症状| 红斑狼疮的症状是什么| 金的部首是什么| 12岁是什么礼| 吃西瓜不能吃什么| 维脑路通又叫什么| 赤子之心什么意思| nana是什么意思| 中耳炎挂什么科| 糖尿病适合喝什么饮料| 9.3号是什么星座| 紫米和黑米有什么区别| 男人小便刺痛吃什么药| 胃不舒服恶心想吐吃什么药| 清胃火吃什么药| 柔和是什么意思| 芊字五行属什么| 嗓子不舒服挂什么科| 5月10号是什么星座| 吃丹参有什么好处| 芒果不能跟什么一起吃| 好嘞是什么意思| 为什么家里会有蟑螂| 桃胶和什么相克| 淀粉酶是查什么的| 4月28日是什么星座| 蛇为什么怕雄黄| 交泰殿是干什么的| 什么是善良| 什么杯子喝水最健康| 心悸吃什么药| 蚊香对人体有什么危害| 百香果是什么季节的水果| 上房是什么意思| 尿隐血弱阳性什么意思| apn是什么意思| 喝碳酸饮料有什么危害| 喝蜂蜜水对身体有什么好处| 阿哥是什么意思| 牛油果树长什么样| 什么是中出| 什么是呼吸性碱中毒| 女性做B超挂什么科| 是代表什么意思| 胆囊炎需要注意什么| 1月1日是什么星座| d是什么单位| 毓婷是什么| 孕妇晚餐吃什么比较好| 什么是肺纤维化| socks是什么意思| 高密度脂蛋白胆固醇偏低什么意思| 女人梦见掉牙齿是什么征兆| cd56阳性是什么意思| 密送是什么意思| 孕酮低什么原因造成的| 什么叫玄学| gson是什么牌子| 嘴巴下面长痘痘是什么原因引起的| 蛞蝓是什么| 什么助听器| 霉菌性阴道炎用什么药最好| 骑士是什么意思| 脸长的人适合什么发型| 常吃南瓜有什么好处和坏处| 刚怀孕吃什么水果对胎儿好| 肠上皮化生是什么意思| 阿莫西林主要治疗什么| 吃丝瓜有什么好处| 大姨妈不能吃什么水果| 曹休和曹操什么关系| 黑洞是什么东西| 曹操属什么生肖| 百度Jump to content

车讯:搭互联系统 风神AX7智驭型12月27日上市

From Wikipedia, the free encyclopedia
(Redirected from Fopen)
百度 在总统府入口处,习近平受到罗塞夫热情迎接,两国元首亲切握手,互致问候。

The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header <stdio.h>.[1] The functionality descends from a "portable I/O package" written by Mike Lesk at Bell Labs in the early 1970s,[2] and officially became part of the Unix operating system in Version 7.[3]

The I/O functionality of C is fairly low-level by modern standards; C abstracts all file operations into operations on streams of bytes, which may be "input streams" or "output streams". Unlike some earlier programming languages, C has no direct support for random-access data files; to read from a record in the middle of a file, the programmer must create a stream, seek to the middle of the file, and then read bytes in sequence from the stream.

The stream model of file I/O was popularized by Unix, which was developed concurrently with the C programming language itself. The vast majority of modern operating systems have inherited streams from Unix, and many languages in the C programming language family have inherited C's file I/O interface with few if any changes (for example, PHP).

Overview

[edit]

This library uses what are called streams to operate with physical devices such as keyboards, printers, terminals or with any other type of files supported by the system. Streams are an abstraction to interact with these in a uniform way. All streams have similar properties independent of the individual characteristics of the physical media they are associated with.[4]

Functions

[edit]

Most of the C file input/output functions are defined in <stdio.h> (or in the C++ header cstdio, which contains the standard C functionality but in the std namespace).

Byte
character
Wide
character
Description
File access fopen Opens a file (with a non-Unicode filename on Windows and possible UTF-8 filename on Linux)
popen opens a process by creating a pipe, forking, and invoking the shell
freopen Opens a different file with an existing stream
fflush Synchronizes an output stream with the actual file
fclose Closes a file
pclose closes a stream
setbuf Sets the buffer for a file stream
setvbuf Sets the buffer and its size for a file stream
fwide Switches a file stream between wide-character I/O and narrow-character I/O
Direct
input/output
fread Reads from a file
fwrite Writes to a file
Unformatted
input/output
fgetc
getc
fgetwc
getwc
Reads a byte/wchar_t from a file stream
fgets fgetws Reads a byte/wchar_t line from a file stream
fputc
putc
fputwc
putwc
Writes a byte/wchar_t to a file stream
fputs fputws Writes a byte/wchar_t string to a file stream
getchar getwchar Reads a byte/wchar_t from stdin
gets Reads a byte string from stdin until a newline or end of file is encountered (deprecated in C99, removed from C11)
putchar putwchar Writes a byte/wchar_t to stdout
puts Writes a byte string to stdout
ungetc ungetwc Puts a byte/wchar_t back into a file stream
Formatted
input/output
scanf
fscanf
sscanf
wscanf
fwscanf
swscanf
Reads formatted byte/wchar_t input from stdin,
a file stream or a buffer
vscanf
vfscanf
vsscanf
vwscanf
vfwscanf
vswscanf
Reads formatted input byte/wchar_t from stdin,
a file stream or a buffer using variable argument list
printf
fprintf
sprintf
snprintf
wprintf
fwprintf
swprintf
Prints formatted byte/wchar_t output to stdout,
a file stream or a buffer
vprintf
vfprintf
vsprintf
vsnprintf
vwprintf
vfwprintf
vswprintf
Prints formatted byte/wchar_t output to stdout,
a file stream, or a buffer using variable argument list
perror Writes a description of the current error to stderr
File positioning ftell
ftello
Returns the current file position indicator
fseek
fseeko
Moves the file position indicator to a specific location in a file
fgetpos Gets the file position indicator
fsetpos Moves the file position indicator to a specific location in a file
rewind Moves the file position indicator to the beginning in a file
Error
handling
clearerr Clears errors
feof Checks for the end-of-file
ferror Checks for a file error
Operations
on files
remove Erases a file
rename Renames a file
tmpfile Returns a pointer to a temporary file
tmpnam Returns a unique filename

Constants

[edit]

Constants defined in the <stdio.h> header include:

Name Notes
EOF A negative integer of type int used to indicate end-of-file conditions
BUFSIZ An integer which is the size of the buffer used by the setbuf() function
FILENAME_MAX The size of a char array which is large enough to store the name of any file that can be opened
FOPEN_MAX The number of files that may be open simultaneously; will be at least eight
_IOFBF An abbreviation for "input/output fully buffered"; it is an integer which may be passed to the setvbuf() function to request block buffered input and output for an open stream
_IOLBF An abbreviation for "input/output line buffered"; it is an integer which may be passed to the setvbuf() function to request line buffered input and output for an open stream
_IONBF An abbreviation for "input/output not buffered"; it is an integer which may be passed to the setvbuf() function to request unbuffered input and output for an open stream
L_tmpnam The size of a char array which is large enough to store a temporary filename generated by the tmpnam() function
NULL A macro expanding to the null pointer constant; that is, a constant representing a pointer value which is guaranteed not to be a valid address of an object in memory
SEEK_CUR An integer which may be passed to the fseek() function to request positioning relative to the current file position
SEEK_END An integer which may be passed to the fseek() function to request positioning relative to the end of the file
SEEK_SET An integer which may be passed to the fseek() function to request positioning relative to the beginning of the file
TMP_MAX The maximum number of unique filenames generable by the tmpnam() function; will be at least 25

Variables

[edit]

Variables defined in the <stdio.h> header include:

Name Notes
stdin A pointer to a FILE which refers to the standard input stream, usually a keyboard.
stdout A pointer to a FILE which refers to the standard output stream, usually a display terminal.
stderr A pointer to a FILE which refers to the standard error stream, often a display terminal.

Member types

[edit]

Data types defined in the <stdio.h> header include:

  • FILE – also known as a file handle or a FILE pointer, this is an opaque pointer containing the information about a file or text stream needed to perform input or output operations on it, including:
    • platform-specific identifier of the associated I/O device, such as a file descriptor
    • the buffer
    • stream orientation indicator (unset, narrow, or wide)
    • stream buffering state indicator (unbuffered, line buffered, fully buffered)
    • I/O mode indicator (input stream, output stream, or update stream)
    • binary/text mode indicator
    • end-of-file indicator
    • error indicator
    • the current stream position and multibyte conversion state (an object of type mbstate_t)
    • reentrant lock (required as of C11)
  • fpos_t – a non-array type capable of uniquely identifying the position of every byte in a file and every conversion state that can occur in all supported multibyte character encodings
  • size_t – an unsigned integer type which is the type of the result of the sizeof operator.

Extensions

[edit]

The POSIX standard defines several extensions to stdio in its Base Definitions, among which are a readline function that allocates memory, the fileno and fdopen functions that establish the link between FILE objects and file descriptors, and a group of functions for creating FILE objects that refer to in-memory buffers.[5]

Example

[edit]

The following C program opens a binary file called myfile, reads five bytes from it, and then closes the file.

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char buffer[5];
    size_t len;
    FILE* fp = fopen("myfile", "rb");

    if (fp == NULL) {
        perror("Failed to open file \"myfile\"");
        return EXIT_FAILURE;
    }

    if ((len = fread(buffer, 1, 5, fp)) < 0) {
        fclose(fp);
        fputs("An error occurred while reading the file.\n", stderr);
        return EXIT_FAILURE;
    }

    fclose(fp);

    printf("The bytes read were: ");
    for (int i = 0; i < len; ++i) {
        printf("%02X ", buffer[i]);
    }
    putchar('\n');

    return EXIT_SUCCESS;
}

Alternatives to stdio

[edit]

Several alternatives to stdio have been developed. Among these is the C++ iostream library, part of the ISO C++ standard. ISO C++ still requires the stdio functionality.

Other alternatives include the Sfio[6] (A Safe/Fast I/O Library) library from AT&T Bell Laboratories. This library, introduced in 1991, aimed to avoid inconsistencies, unsafe practices and inefficiencies in the design of stdio. Among its features is the possibility to insert callback functions into a stream to customize the handling of data read from or written to the stream.[7] It was released to the outside world in 1997, and the last release was 1 February 2005.[8]

See also

[edit]

References

[edit]
  1. ^ ISO/IEC 9899:1999 specification. p. 274, § 7.19.
  2. ^ Kernighan, Brian; Pike, Rob (1984). The UNIX Programming Environment. Englewood Cliffs: Prentice Hall. p. 200. Bibcode:1984upe..book.....K.
  3. ^ McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139.
  4. ^ "(stdio.h) - C++ Reference". C++. Retrieved 25 July 2021.
  5. ^ stdio.h – Base Definitions Reference, The Single UNIX Specification, Version 5 from The Open Group
  6. ^ "Sfio: A Safe/Fast I/O Library". Archived from the original on 11 February 2006. Retrieved 16 March 2021.{{cite web}}: CS1 maint: bot: original URL status unknown (link)
  7. ^ Korn, David G.; Vo, Kiem-Phong (1991). SFIO: Safe/Fast String/File IO. Proc. Summer USENIX Conf. CiteSeerX 10.1.1.51.6574.
  8. ^ Fowler, Glenn S.; Korn, David G.; Vo, Kiem-Phong (2000). Extended Formatting with Sfio. Proc. Summer USENIX Conf.
[edit]
氟康唑治什么妇科炎症 什么的树影 凝血五项是检查什么病 什么是肾炎 94年属于什么生肖
山药和什么不能一起吃 为什么感觉 男人吃海参有什么好处 先兆流产是什么意思 眼泪为什么是咸的
孩子打嗝是什么原因 什么是记忆棉 炖牛肉放什么调料 8月10号是什么星座 指甲盖凹陷是什么原因
荟萃是什么意思 什么症状吃保心丸 什么是梦 梦见上香是什么意思 减肥最好的办法是什么
熬夜吃什么对身体好hcv8jop3ns7r.cn 静的部首是什么hcv9jop6ns7r.cn pha是什么意思ff14chat.com 猫咪呕吐吃什么药可以解决hcv9jop0ns4r.cn 人体有365个什么baiqunet.com
小仙女是什么意思hcv8jop0ns7r.cn 为什么老是出汗creativexi.com 舍友什么意思hcv9jop3ns1r.cn 黎明破晓是什么意思hcv7jop6ns5r.cn 葛粉吃了有什么好处hcv8jop9ns1r.cn
武则天叫什么名字hcv7jop6ns2r.cn 黄花菜都凉了是什么意思hcv9jop6ns0r.cn 喉咙痒咳嗽用什么药hcv9jop2ns5r.cn 肉桂茶是什么茶hcv9jop7ns0r.cn 眼睛痒吃什么药onlinewuye.com
惊为天人是什么意思hcv9jop3ns8r.cn 三月七号是什么星座hcv8jop8ns6r.cn 走仕途是什么意思helloaicloud.com 办准生证需要什么资料clwhiglsz.com 晚上睡觉牙齿出血是什么原因hcv8jop6ns7r.cn
百度