zoukankan      html  css  js  c++  java
  • C fgetc

    格式:int fgetc(FILE *stream);
    这个函数的返回值,是返回所读取的一个字节。如果读到文件末尾或者读取出错时返回EOF。
    位于stdio.h中。从流中读取字符,即从stream所指定的文件中取得下一个字符。这里需要注意,在每取完一个字符时stream会自动向下移动一个字节。这样编程时,程序员就不用再对stream控制了。这种功能在许多读写函数中都有体现。
     
    例子
    #include <string.h> 
    #include <stdio.h> 
    #include <conio.h> 
    int main(void) 
    {
        FILE *stream;
        char string[ ] = "This is a test";
        int ch; 
         
        /* open a file for update */
        stream = fopen("DUMMY.FIL", "w+"); 
         
        /* write a string into the file */
        fwrite(string, strlen(string), 1, stream); 
     
        /* seek to the beginning of the file */
        fseek(stream, 0, SEEK_SET);
        do
        {
            /* read a char from the file */
            ch = fgetc(stream);
            /* display the character */
            putch(ch);
        }
        while (ch != EOF);
        fclose(stream);
        return 0;
    }
  • 相关阅读:
    MongoDB入门示例及介绍
    Oracle/PLSQL CURSOR FOR Loop
    JAVA写的文件分割与文件合并程序
    synchronized 解决死锁的问题 轉貼
    采用批处理命令对文件进行解压及采用SQLCMD进行数据库挂载
    chapter6作业
    chapter5作业
    chapter4作业
    Linuz系统管理 -----账号管理
    chapter02
  • 原文地址:https://www.cnblogs.com/alsofly/p/3725224.html
Copyright © 2011-2022 走看看