正文

C语言的文件操作2007-09-02 21:46:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/progfan/29073.html

分享到:

#include <sys\stat.h> #include <string.h> #include <fcntl.h> #include <io.h> int main(void) {    int handle;   //句柄方式   char buf[11] = "0123456789";    /* change the default file mode from text to binary */    _fmode = O_BINARY;    /* create a binary file for reading and writing */    handle = creat("DUMMY.FIL", S_IREAD | S_IWRITE);    /* write 10 bytes to the file */    write(handle, buf, strlen(buf));    /* close the file */    close(handle);    return 0; } #include <stdio.h> int main(void) {    FILE *fp;   //指针方式   char ch;    /* open a file for writing */    fp = fopen("DUMMY.FIL", "w");    /* force an error condition by attempting to read */    ch = fgetc(fp);    printf("%c\n",ch);    if (ferror(fp))    {       /* display an error message */       printf("Error reading from DUMMY.FIL\n");       /* reset the error and EOF indicators */       clearerr(fp);    }    fclose(fp);    return 0; }

阅读(31) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册