zoukankan      html  css  js  c++  java
  • C语言读写文件

    FOPEN(3) Linux Programmer’s Manual FOPEN(3)

    NAME
    fopen, fdopen, freopen - stream open functions

    SYNOPSIS
    #include <stdio.h>

    FILE *fopen(const char *path, const char *mode);
    FILE *fdopen(int fildes, const char *mode);
    FILE *freopen(const char *path, const char *mode, FILE *stream);

    DESCRIPTION
    The fopen() function opens the file whose name is the string pointed to by path and associates a
    stream with it.

    The argument mode points to a string beginning with one of the following sequences (Additional
    characters may follow these sequences.):

    r Open text file for reading. The stream is positioned at the beginning of the file.

    r+ Open for reading and writing. The stream is positioned at the beginning of the file.

    w Truncate file to zero length or create text file for writing. The stream is positioned at
    the beginning of the file.

    w+ Open for reading and writing. The file is created if it does not exist, otherwise it is
    truncated. The stream is positioned at the beginning of the file.

    a Open for appending (writing at end of file). The file is created if it does not exist.
    The stream is positioned at the end of the file.

    a+ Open for reading and appending (writing at end of file). The file is created if it does
    not exist. The initial file position for reading is at the beginning of the file, but out-
    put is always appended to the end of the file.

    The mode string can also include the letter ‘‘b’’ either as a last character or as a character
    between the characters in any of the two-character strings described above. This is strictly for
    compatibility with C89 and has no effect; the ‘‘b’’ is ignored on all POSIX conforming systems,
    including Linux. (Other systems may treat text files and binary files differently, and adding the
    ‘‘b’’ may be a good idea if you do I/O to a binary file and expect that your program may be ported
    to non-Unix environments.)

    Any created files will have mode S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH (0666), as modi-
    fied by the process’ umask value (see umask(2)).

    FREAD(3) Linux Programmer’s Manual FREAD(3)

    NAME
    fread, fwrite - binary stream input/output

    SYNOPSIS
    #include <stdio.h>

    size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);

    size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);

    DESCRIPTION
    The function fread() reads nmemb elements of data, each size bytes long, from the stream pointed
    to by stream, storing them at the location given by ptr.

    The function fwrite() writes nmemb elements of data, each size bytes long, to the stream pointed
    to by stream, obtaining them from the location given by ptr.

    For non-locking counterparts, see unlocked_stdio(3).

    RETURN VALUE
    fread() and fwrite() return the number of items successfully read or written (i.e., not the number
    of characters). If an error occurs, or the end-of-file is reached, the return value is a short
    item count (or zero).

    fread() does not distinguish between end-of-file and error, and callers must use feof(3) and fer-
    ror(3) to determine which occurred.

  • 相关阅读:
    【转载】zookeeper数据模型
    java.util.logging使用笔记2
    spark提交应用的方法(spark-submit)
    spark集群模式概述
    [spark]spark 编程教程
    [spark]Spark Streaming教程
    使用github pages创建博客
    spark 编程教程
    Spark编程指南V1.4.0(翻译)
    mysql基本操作
  • 原文地址:https://www.cnblogs.com/xuelei/p/4569886.html
Copyright © 2011-2022 走看看