zoukankan      html  css  js  c++  java
  • c 标准io <stdio.h>

    读文件到文件尾

        FILE *file;
        if((file = fopen("D://a.txt","r")) == NULL)
        {
            printf("cant open file!");
        }
        char ch;
        while((ch = fgetc(file))!=EOF) putchar(ch);
        if(fclose(file)) printf("file close error!");

    从键盘输入字符存入文件

        FILE *file;
        if((file = fopen("D://a.txt","w")) == NULL)
        {
            printf("cant open file!");
        }
        char ch;
        while((ch = fgetchar()!='\n')) fputc(ch,file);
        if(fclose(file)) printf("file close error!");

    读写字符串

    char * fgets(char *str,int num,FILE *file)
    char * fputs(char *str,FILE *file)
    #include <stdio.h>
    #include <string.h>
    main(){
        FILE * fp1, *fp2;
        char str[128];
        if((fp1 = fopen("text1.txt","r"))==NULL)
        {
            /*以只读方式打开文件1*/
            printf("can not open file \n")
            exit(0);
        }
        if((fp2 = fopen("test2.txt","w")) == NULL){
            /*以只写方式打开文件2*/
            printf("can not open file\n");
            exit(0);        
        }
        while((strlen(fgets(str,128,fp1)))>0)
        /*从文件中读回字符串长如大于0*/
        printf("%s",str);
        /*在屏幕显示*/
        fclose(fp1);
        fclose(fp2);
    }

    获取文件长度

        fseek (file, 0, SEEK_END);   // non-portable
        int size=ftell (file);
        rewind (file);

    成块读写文件

    fread
    fwrite
  • 相关阅读:
    POST GET原理函数
    位宽与带宽
    编程小工具
    C#的四个基本技巧
    关闭弹出模态窗口以后刷新父窗口
    十年技术,不要再迷茫
    冒泡排序
    单元测试工具及资源推荐
    xml xhtml html dhtml的区别
    删除List<string>中重复的值
  • 原文地址:https://www.cnblogs.com/wangjixianyun/p/2983629.html
Copyright © 2011-2022 走看看