现在的位置: 首页 > 综合 > 正文

C语言操作文件

2013年04月03日 ⁄ 综合 ⁄ 共 677字 ⁄ 字号 评论关闭

http://blog.chinaunix.net/u1/37000/showart_338364.html

 

 

// C语言读写文件.cpp : 定义控制台应用程序的入口点。
//

#include "stdio.h"
#include "string.h"

void write()
{
    FILE *fp;
    //只写打开或建立一个文本文件,只允许写数据
    fp=fopen("D:\\c.txt","wt");
    if(fp!=NULL)
    {
        char *str="C语言创建txt";
        //fputs(str,fp);
        fwrite(str,strlen(str),1,fp);
        
    }
    //fflush(fp);
    fclose(fp);
}

void read()
{
    FILE *fp;
    //只读打开一个文本文件,只允许读数据
    fp=fopen("D:\\c.txt","rt");
    if(fp!=NULL)
    {
        printf("文件大小为:%d\n",99);
    }else
    {
        printf("出错\n");
    }
    fclose(fp);
}
void main()
{
    //read();
    long size;
    FILE *fp;
    
    fp=fopen("D:\\c.txt","rb");
    fseek(fp,0,SEEK_END);
    size=ftell(fp);

    fclose(fp);
    printf("%d\n",size);

}

 

抱歉!评论已关闭.