Home  >  Article  >  Backend Development  >  What are the file reading and writing functions in C language?

What are the file reading and writing functions in C language?

烟雨青岚
烟雨青岚Original
2020-07-06 10:06:403875browse

c语言文件读写函数有:“fgetc”和“fputc”(字符读写函数)、“fgets”和“fputs”(字符串读写函数)、“freed”和“fwrite”(数据块读写函数)、“fscanf”和“fprinf”(格式化读写函数)。

What are the file reading and writing functions in C language?

对文件的读和写是最常用的文件操作。

在C语言中提供了多种文件读写的函数:

字符读写函数  :fgetc和fputc

字符串读写函数:fgets和fputs

数据块读写函数:freed和fwrite

格式化读写函数:fscanf和fprinf

下面分别予以介绍。使用以上函数都要求包含头文件stdio.h。

示例:

#include
main(){
    FILE *fp;
    char ch;
    if((fp=fopen("d:\\jrzh\\example\\c1.txt","rt"))==NULL){
        printf("\nCannot open file strike any key exit!");
        getch();
        exit(1);
    }
    ch=fgetc(fp);
    while(ch!=EOF){
        putchar(ch);
        ch=fgetc(fp);
    }
    fclose(fp);
}

推荐教程:《C语言

The above is the detailed content of What are the file reading and writing functions in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn