格式: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;
}

C fgetc的更多相关文章

  1. Linux C 文件输入输出函数 fopen()、getc()/fgetc()、putc()/fputc()、fclose()、fprintf()、fscanf()、fgets()、fputs()、fseek()、ftell()、fgetpos()、fsetpos() 详解

      fopen(打开文件) 定义函数 FILE * fopen(const char * path,const char * mode); 函数说明 参数path字符串包含欲打开的文件路径及文件名,参 ...

  2. fgetc和fputc函数

    1.输入函数 以下三个函数可用于一次读一个字符. #include <stdio.h> int getc( FILE *fp ); int fgetc( FILE *fp ); int g ...

  3. (转载)C++文件读写函数之——fopen、fread和fwrite、fgetc和fputc、fgets和fputs、ftellf和fseek、rewind

    http://blog.sina.com.cn/s/blog_61437b3b0102v0bt.html http://blog.csdn.net/chenwk891/article/details/ ...

  4. 5.4.1 termios结构,关闭回显功能,一键入字符fgetc立刻返回,不用按下回车键

    Linux提供了一组编程接口,用来控制终端驱动程序的行为.这样我们可以更精细的来控制终端. 例如: 回显:允许控制字符的回显,例如读取密码时. 使用termios结构的密码程序 #include &l ...

  5. C++之函数fgetc和fputc、fgets和fputs、fread和fwrite、fscanf和fprintf用法小结

    #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; int ...

  6. PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数

    fread().fgets().fgetc().file_get_contents() 与 file() 函数用于从文件中读取内容. fread() fread() 函数用于读取文件(可安全用于二进制 ...

  7. C语言中fgetc、fputc和getc、putc的区别是什么

    看书的时候,发现了这四个函数,想知道他们的不同.结果上网查发现很多人说fgetc.fputc的f代表的是file,就是这两个函数是和文件有关的!但是一看他们的函数声明,如下图: 发现他们的参数里面都有 ...

  8. 字符的读写函数:fgetc()和fputc()

    fgetc();    功能:    从文件中读取字符.    头文件:  #include <stdio.h>    函数原型:int fgetc(FILE *stream);    返 ...

  9. 三、fgetc与fputc

    fgetc 功能:从流中读取一个字符 原型:int fgetc(FILE *stream); 参数: stream:要读取的流指针 返回:读取到的字符,如果读完则返回EOF,EOF是end of fi ...

随机推荐

  1. MyEclispe发布web项目-遁地龙卷风

    (-1)写在前面 我用的是MyEclipse8.5. 还记得以前帮助一个女同学解决问题的时候,特意情调了要先启动服务在发布项目,其实单独的时候都是知道的,总和起来后就容易片面的给出结论.因为不会发生问 ...

  2. PHP 动态生成验证码

    ……机器人会在网站中搜寻允许他们插入广告的输入表单,在虚拟世界没有什么能阻挡它们胡作非为.这些机器人效率极高,完全不关心所攻击的表单的本来用途.它们唯一的目标就是用它们的垃圾广告覆盖你的内容,残忍地为 ...

  3. Python日志logging

    logging 用于便捷记录日志且线程安全的模块 1.单文件日志 import logging logging.basicConfig(filename='log.log', format='%(as ...

  4. angularjs向后台传参,后台收不到数据

    angularjs中封装了一个$http服务,用来请求远程资源 参见:HTTP API 其中封装过的$http.post和$http.get使用起来比较方便 后台是php,用$_POST['name' ...

  5. libevent在windows平台下通过vs进行编译

    1.vs中新建一个静态库项目 2.配置头文件目录,将./compat../include../WIN32-Code三个目录添加到文件目录中 3.用记事本打开Makefile.nmake文件,可以看到里 ...

  6. linux 使用 nvidia 的 gpu

    第一种方法: [Wizard@Wizard ~]$ nvidia-detect kmod-nvidiaOptimus hardware detected: An Intel display contr ...

  7. 曲线救国:IIS7集成模式下如何获取网站的URL

    如果我们在Global中的Application_Start事件中访问HttpContext.Current.Request对象,如: protected void Application_Start ...

  8. 各种浏览器的Hack写法(chrome firefox ie等)

    Hack是针对不同的浏览器去写不同的CSS样式,从而让各浏览器能达到一致的渲染效果,那么针对不同的浏览器写不同的CSS CODE的过程,就叫CSS HACK,同时也叫写CSS Hack. 然后将Hac ...

  9. 多个DataSet数据合并

    DataSet ds = myIAppSet.GetHomeHottestList(siteID, , time); ].Rows.Count > ) { ds.Merge(ds1); } Me ...

  10. android 第三方登录 --- QQ

    1,jar包 2,配置AndroidManifest.xml <activity android:name=".login.LoginActivity" android:co ...